compat_string.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #ifndef TOR_COMPAT_STRING_H
  6. #define TOR_COMPAT_STRING_H
  7. #include "orconfig.h"
  8. #include "lib/cc/compat_compiler.h"
  9. #include <stddef.h>
  10. /* ===== String compatibility */
  11. #ifdef _WIN32
  12. /* Windows doesn't have str(n)casecmp, but mingw defines it: only define it
  13. * ourselves if it's missing. */
  14. #ifndef HAVE_STRNCASECMP
  15. static inline int strncasecmp(const char *a, const char *b, size_t n);
  16. static inline int strncasecmp(const char *a, const char *b, size_t n) {
  17. return strncmpi(a,b);
  18. }
  19. #endif
  20. #ifndef HAVE_STRCASECMP
  21. static inline int strcasecmp(const char *a, const char *b, size_t n);
  22. static inline int strcasecmp(const char *a, const char *b, size_t n) {
  23. return strcmpi(a,b);
  24. }
  25. #endif
  26. #endif
  27. #if defined __APPLE__
  28. /* On OSX 10.9 and later, the overlap-checking code for strlcat would
  29. * appear to have a severe bug that can sometimes cause aborts in Tor.
  30. * Instead, use the non-checking variants. This is sad.
  31. *
  32. * See https://trac.torproject.org/projects/tor/ticket/15205
  33. */
  34. #undef strlcat
  35. #undef strlcpy
  36. #endif /* defined __APPLE__ */
  37. #ifndef HAVE_STRLCAT
  38. size_t strlcat(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2));
  39. #endif
  40. #ifndef HAVE_STRLCPY
  41. size_t strlcpy(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2));
  42. #endif
  43. char *tor_strtok_r_impl(char *str, const char *sep, char **lasts);
  44. #ifdef HAVE_STRTOK_R
  45. #define tor_strtok_r(str, sep, lasts) strtok_r(str, sep, lasts)
  46. #else
  47. #define tor_strtok_r(str, sep, lasts) tor_strtok_r_impl(str, sep, lasts)
  48. #endif
  49. #endif