You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
1.2 KiB

  1. #define _GNU_SOURCE
  2. #include <stdarg.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <dlfcn.h>
  6. #include <unistd.h>
  7. #include <stdio.h>
  8. int vprintf(const char *format, va_list ap) {
  9. if (strncmp(format, "profiling:", strlen("profiling:")) == 0)
  10. return 0;
  11. static int (*func_fprintf)(const char *format, va_list ap) = NULL;
  12. if (func_fprintf == NULL)
  13. func_fprintf = (int (*)(const char *format, va_list ap))dlsym(RTLD_NEXT, "vprintf");
  14. return func_fprintf(format, ap);
  15. }
  16. int printf(const char *format, ...) {
  17. va_list ap;
  18. va_start(ap, format);
  19. int res = vprintf(format, ap);
  20. va_end(ap);
  21. return res;
  22. }
  23. int vfprintf(FILE *stream, const char *format, va_list ap) {
  24. if (strncmp(format, "profiling:", strlen("profiling:")) == 0)
  25. return 0;
  26. static int (*func_vfprintf)(FILE * stream, const char *format, va_list ap) = NULL;
  27. if (func_vfprintf == NULL)
  28. func_vfprintf = (int (*)(FILE * stream, const char *format, va_list ap))dlsym(RTLD_NEXT, "vfprintf");
  29. return func_vfprintf(stream, format, ap);
  30. }
  31. int fprintf(FILE *stream, const char *format, ...) {
  32. va_list ap;
  33. va_start(ap, format);
  34. int res = vfprintf(stream, format, ap);
  35. va_end(ap);
  36. return res;
  37. }