I am trying to intercept calls on printfusing a parameter ld -wrap. I have two files:
main.c:
#include <stdio.h>
int main(void) {
printf("printing\n");
printf("printing");
}
printf_wrapper.c:
int __real_printf(const char *format, ...);
int __wrap_printf(const char *format, ...) {
(void)format;
return __real_printf("WRAPPED\n");
}
And I compile the following command:
gcc -Wl,-wrap,printf *.c
When I run the resulting binary a.out, I get this output:
printing
WRAPPED
Why does the wrapper fail if there is a new line in the line? I checked the system stdio.h, and printf is not a macro. This is with gcc 5.3.0
source
share