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 */
7 * \file compat_string.h
8 * \brief Header for compat_string.c
11 #ifndef TOR_COMPAT_STRING_H
12 #define TOR_COMPAT_STRING_H
15 #include "lib/cc/compat_compiler.h"
19 /* ===== String compatibility */
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
);
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
) {
34 #endif /* !defined(HAVE_STRCASECMP) */
35 #endif /* defined(_WIN32) */
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.
42 * (If --enable-fragile-hardening is passed to configure, we use the hardened
43 * variants, which do not suffer from this issue.)
45 * See https://bugs.torproject.org/tpo/core/tor/15205.
49 #endif /* defined __APPLE__ */
52 size_t strlcat(char *dst
, const char *src
, size_t siz
);
55 size_t strlcpy(char *dst
, const char *src
, size_t siz
);
58 char *tor_strtok_r_impl(char *str
, const char *sep
, char **lasts
);
60 #define tor_strtok_r(str, sep, lasts) strtok_r(str, sep, lasts)
62 #define tor_strtok_r(str, sep, lasts) tor_strtok_r_impl(str, sep, lasts)
65 #endif /* !defined(TOR_COMPAT_STRING_H) */