compat_string.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. /**
  6. * \file compat_string.h
  7. * \brief Header for compat_string.c
  8. **/
  9. #ifndef TOR_COMPAT_STRING_H
  10. #define TOR_COMPAT_STRING_H
  11. #include "orconfig.h"
  12. #include "lib/cc/compat_compiler.h"
  13. #include <stddef.h>
  14. /* ===== String compatibility */
  15. #ifdef _WIN32
  16. /* Windows doesn't have str(n)casecmp, but mingw defines it: only define it
  17. * ourselves if it's missing. */
  18. #ifndef HAVE_STRNCASECMP
  19. static inline int strncasecmp(const char *a, const char *b, size_t n);
  20. static inline int strncasecmp(const char *a, const char *b, size_t n) {
  21. return _strnicmp(a,b,n);
  22. }
  23. #endif
  24. #ifndef HAVE_STRCASECMP
  25. static inline int strcasecmp(const char *a, const char *b);
  26. static inline int strcasecmp(const char *a, const char *b) {
  27. return _stricmp(a,b);
  28. }
  29. #endif
  30. #endif
  31. #if defined __APPLE__
  32. /* On OSX 10.9 and later, the overlap-checking code for strlcat would
  33. * appear to have a severe bug that can sometimes cause aborts in Tor.
  34. * Instead, use the non-checking variants. This is sad.
  35. *
  36. * See https://trac.torproject.org/projects/tor/ticket/15205
  37. */
  38. #undef strlcat
  39. #undef strlcpy
  40. #endif /* defined __APPLE__ */
  41. #ifndef HAVE_STRLCAT
  42. size_t strlcat(char *dst, const char *src, size_t siz);
  43. #endif
  44. #ifndef HAVE_STRLCPY
  45. size_t strlcpy(char *dst, const char *src, size_t siz);
  46. #endif
  47. char *tor_strtok_r_impl(char *str, const char *sep, char **lasts);
  48. #ifdef HAVE_STRTOK_R
  49. #define tor_strtok_r(str, sep, lasts) strtok_r(str, sep, lasts)
  50. #else
  51. #define tor_strtok_r(str, sep, lasts) tor_strtok_r_impl(str, sep, lasts)
  52. #endif
  53. #endif