freopen.c 460 B

123456789101112131415161718
  1. #include <stdio.h>
  2. #include <dlfcn.h>
  3. #include <string.h>
  4. static FILE * (*original_freopen)(const char *pathname, const char *mode, FILE *stream);
  5. static void __attribute ((constructor)) freopen_hook_init(void) {
  6. original_freopen = dlsym(dlopen ("/lib/libc.so.0", RTLD_LAZY), "freopen");
  7. }
  8. FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
  9. if(stream == stdout) return stdout;
  10. return original_freopen(pathname, mode, stream);
  11. }