Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #define _GNU_SOURCE
  2.  
  3. #include <dlfcn.h>
  4. #include <assert.h>
  5.  
  6. #define LOAD_ADDRESS(var, str) \
  7. if (var == 0) \
  8. if ((var = dlsym (RTLD_NEXT, str)) == 0) \
  9. __builtin_abort ()
  10.  
  11.  
  12. int
  13. strcmp (const char *s1, const char *s2)
  14. {
  15. static int (*libc_strcmp)(const char *, const char *) = 0;
  16.  
  17. assert (s1);
  18. assert (s2);
  19.  
  20. LOAD_ADDRESS (libc_strcmp, "strcmp");
  21.  
  22. return libc_strcmp (s1, s2);
  23. }
  24.  
  25.  
  26. int
  27. strncmp (const char *s1, const char *s2, size_t n)
  28. {
  29. static int (*libc_strncmp)(const char *, const char *, size_t) = 0;
  30.  
  31. assert (s1);
  32. assert (s2);
  33.  
  34. LOAD_ADDRESS (libc_strncmp, "strncmp");
  35.  
  36. return libc_strncmp (s1, s2, n);
  37. }
  38.  
  39. int
  40. memcmp (const char *s1, const char *s2, size_t n)
  41. {
  42. static int (*libc_memcmp)(const char *, const char *, size_t) = 0;
  43.  
  44. assert (s1);
  45. assert (s2);
  46.  
  47. LOAD_ADDRESS (libc_memcmp, "memcmp");
  48.  
  49. return libc_memcmp (s1, s2, n);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement