PDA

View Full Version : how to override stdio.h "remove"?


jccheng
10th December 2004, 05:11 AM
I've got a C project where I have to override system calls such as open, close, read, write, etc. But when I try to override "remove", the gcc compiler complains:
error: conflicting types for 'remove'
/usr/include/stdio.h:154: error: previous declaration of 'remove' was here
The compiler didn't complain about the other functions, only remove. And, obviously if I leave out "#include <stdio.h>", I can't use any of the other functions. I've googled around but couldn't find anything useful. Any help/advice would be greatly appreciated. Thanks.

rogue
10th December 2004, 06:12 AM
You could preload your own library functions (http://www-106.ibm.com/developerworks/linux/library/l-glibc.html) which would override (be found first by LD (http://www.die.net/doc/linux/man/man8/ld.so.8.html)) any shared library.

rogue
10th December 2004, 06:24 AM
Incidentally, the error is because your function definition for remove() (http://www.opengroup.org/onlinepubs/007908799/xsh/remove.html) differs with the prototype found in stdio.h. :)

jccheng
10th December 2004, 06:33 AM
Thanks for the response, but I think LD_PRELOAD will only work, in my situation, after the library is compiled. The problem is that I have a file, mylib.c, with overridden functions for open, close, read, write, remove, etc. Without the overridden remove function, I can compile mylib.c as a shared library (gcc -shared -o mylib.so mylib.c -ldl) without errors. Then I can "export LD_PRELOAD=mylib.so" and any program hereafter would be using the functions in mylib.so instead of libc.so. However, with the remove function in mylib.c, the library can't compile and LD_PRELOAD can't load mylib.so. I hope that this makes since because this project sure doesn't.

jccheng
10th December 2004, 06:35 AM
You were right... I forgot the "const". Thanks so much, you're a lifesaver!

Incidentally, the error is because your function definition for remove() (http://www.opengroup.org/onlinepubs/007908799/xsh/remove.html) differs with the prototype found in stdio.h. :)

Ikoma Travel Photos on Instagram - Singida Photos on Instagram - Ballymena