How can we replace a C standard library function with our own implementation of that function ?
For example, how can I replace strcpy() with my own implementation of strcpy() and have all calls link to the new implementations instead?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
At least with GCC and glibc, the symbols for the standard C functions are weak and thus you can override them. For example,
strcpy.c:
And build it like this:
and then:
Note the importance of
-fno-builtinhere. If you don’t use this, GCC will replace thestrcpy()call to a builtin function, of which GCC has a number.I’m not sure if this works with other compilers/platforms.