Update copyrights to 2021, using "make update-copyright"
[tor.git] / src / lib / string / compat_string.h
blob57f08580bbf0c49a9facaf51785e632ace02ea72
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 */
6 /**
7 * \file compat_string.h
8 * \brief Header for compat_string.c
9 **/
11 #ifndef TOR_COMPAT_STRING_H
12 #define TOR_COMPAT_STRING_H
14 #include "orconfig.h"
15 #include "lib/cc/compat_compiler.h"
17 #include <stddef.h>
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);
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);
34 #endif /* !defined(HAVE_STRCASECMP) */
35 #endif /* defined(_WIN32) */
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.
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.
47 #undef strlcat
48 #undef strlcpy
49 #endif /* defined __APPLE__ */
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
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
65 #endif /* !defined(TOR_COMPAT_STRING_H) */