tor  0.4.2.0-alpha-dev
compat_string.h
Go to the documentation of this file.
1 /* Copyright (c) 2003-2004, Roger Dingledine
2  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3  * Copyright (c) 2007-2019, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
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  * See https://trac.torproject.org/projects/tor/ticket/15205
43  */
44 #undef strlcat
45 #undef strlcpy
46 #endif /* defined __APPLE__ */
47 
48 #ifndef HAVE_STRLCAT
49 size_t strlcat(char *dst, const char *src, size_t siz);
50 #endif
51 #ifndef HAVE_STRLCPY
52 size_t strlcpy(char *dst, const char *src, size_t siz);
53 #endif
54 
55 char *tor_strtok_r_impl(char *str, const char *sep, char **lasts);
56 #ifdef HAVE_STRTOK_R
57 #define tor_strtok_r(str, sep, lasts) strtok_r(str, sep, lasts)
58 #else
59 #define tor_strtok_r(str, sep, lasts) tor_strtok_r_impl(str, sep, lasts)
60 #endif
61 
62 #endif /* !defined(TOR_COMPAT_STRING_H) */
char * tor_strtok_r_impl(char *str, const char *sep, char **lasts)
Definition: compat_string.c:45
Utility macros to handle different features and behavior in different compilers.