tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

compat_string.h (1974B)


      1 /* Copyright (c) 2003-2004, Roger Dingledine
      2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
      3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
      4 /* See LICENSE for licensing information */
      5 
      6 /**
      7 * \file compat_string.h
      8 * \brief Header for compat_string.c
      9 **/
     10 
     11 #ifndef TOR_COMPAT_STRING_H
     12 #define TOR_COMPAT_STRING_H
     13 
     14 #include "orconfig.h"
     15 #include "lib/cc/compat_compiler.h"
     16 
     17 #include <stddef.h>
     18 
     19 /* ===== String compatibility */
     20 #ifdef _WIN32
     21 /* Windows doesn't have str(n)casecmp, but mingw defines it: only define it
     22 * ourselves if it's missing. */
     23 #ifndef HAVE_STRNCASECMP
     24 static inline int strncasecmp(const char *a, const char *b, size_t n);
     25 static inline int strncasecmp(const char *a, const char *b, size_t n) {
     26  return _strnicmp(a,b,n);
     27 }
     28 #endif /* !defined(HAVE_STRNCASECMP) */
     29 #ifndef HAVE_STRCASECMP
     30 static inline int strcasecmp(const char *a, const char *b);
     31 static inline int strcasecmp(const char *a, const char *b) {
     32  return _stricmp(a,b);
     33 }
     34 #endif /* !defined(HAVE_STRCASECMP) */
     35 #endif /* defined(_WIN32) */
     36 
     37 #if defined __APPLE__
     38 /* On OSX 10.9 and later, the overlap-checking code for strlcat would
     39 * appear to have a severe bug that can sometimes cause aborts in Tor.
     40 * Instead, use the non-checking variants.  This is sad.
     41 *
     42 * (If --enable-fragile-hardening is passed to configure, we use the hardened
     43 * variants, which do not suffer from this issue.)
     44 *
     45 * See https://bugs.torproject.org/tpo/core/tor/15205.
     46 */
     47 #undef strlcat
     48 #undef strlcpy
     49 #endif /* defined __APPLE__ */
     50 
     51 #ifndef HAVE_STRLCAT
     52 size_t strlcat(char *dst, const char *src, size_t siz);
     53 #endif
     54 #ifndef HAVE_STRLCPY
     55 size_t strlcpy(char *dst, const char *src, size_t siz);
     56 #endif
     57 
     58 char *tor_strtok_r_impl(char *str, const char *sep, char **lasts);
     59 #ifdef HAVE_STRTOK_R
     60 #define tor_strtok_r(str, sep, lasts) strtok_r(str, sep, lasts)
     61 #else
     62 #define tor_strtok_r(str, sep, lasts) tor_strtok_r_impl(str, sep, lasts)
     63 #endif
     64 
     65 #endif /* !defined(TOR_COMPAT_STRING_H) */