libnoprofile.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. static int (*func_fprintf)(const char *format, va_list ap) = NULL;
  10. if (func_fprintf == NULL)
  11. func_fprintf = (int (*) (const char *format, va_list ap)) dlsym(RTLD_NEXT, "vprintf");
  12. va_list ap2;
  13. va_copy(ap2, ap);
  14. if (strncmp(format, "profiling:", strlen("profiling:")) == 0)
  15. return 0;
  16. int res = func_fprintf(format, ap2);
  17. va_end(ap2);
  18. return res;
  19. }
  20. int printf(const char *format, ...) {
  21. va_list ap;
  22. va_start(ap, format);
  23. int res = vprintf(format, ap);
  24. va_end(ap);
  25. return res;
  26. }
  27. int vfprintf(FILE *stream, const char *format, va_list ap) {
  28. static int (*func_vfprintf)(FILE *stream, const char *format, va_list ap) = NULL;
  29. if (func_vfprintf == NULL)
  30. func_vfprintf = (int (*) (FILE *stream, const char *format, va_list ap)) dlsym(RTLD_NEXT, "vfprintf");
  31. va_list ap2;
  32. va_copy(ap2, ap);
  33. if (strncmp(format, "profiling:", strlen("profiling:")) == 0)
  34. return 0;
  35. int res = func_vfprintf(stream, format, ap2);
  36. va_end(ap2);
  37. return res;
  38. }
  39. int fprintf(FILE *stream, const char *format, ...) {
  40. va_list ap;
  41. va_start(ap, format);
  42. int res = vfprintf(stream, format, ap);
  43. va_end(ap);
  44. return res;
  45. }