|
I am trying to test errors in read operations (io.read - io.line). Does anyone know a reliable/automatic way to generate a read error on Linux? (That is, a situation where fread returns EOF and ferror returns not zero.) -- Roberto
Something like how the fakeroot does the libc call hijacking. You can write a dynamic library that defines some libc functions: static size_t original_fread(....) = (size_t (*) dlsym(RTLD_NEXT, fread); extern size_t fread(....) { size_t ret = original_fread(....); /* some logic that injects errors */ return ret; } and then run your program like this: LD_PRELOAD=fakelibc.so ./test-program