compat_string.h 1.61 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* Copyright (c) 2003-2004, Roger Dingledine
 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
 * Copyright (c) 2007-2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */

#ifndef TOR_COMPAT_STRING_H
#define TOR_COMPAT_STRING_H

#include "orconfig.h"
#include "lib/cc/compat_compiler.h"

#include <stddef.h>

/* ===== String compatibility */
#ifdef _WIN32
16
17
18
19
20
/* Windows doesn't have str(n)casecmp, but mingw defines it: only define it
 * ourselves if it's missing. */
#ifndef HAVE_STRNCASECMP
static inline int strncasecmp(const char *a, const char *b, size_t n);
static inline int strncasecmp(const char *a, const char *b, size_t n) {
21
  return _strnicmp(a,b,n);
22
23
24
}
#endif
#ifndef HAVE_STRCASECMP
25
26
static inline int strcasecmp(const char *a, const char *b);
static inline int strcasecmp(const char *a, const char *b) {
27
  return _stricmp(a,b);
28
29
}
#endif
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#endif

#if defined __APPLE__
/* On OSX 10.9 and later, the overlap-checking code for strlcat would
 * appear to have a severe bug that can sometimes cause aborts in Tor.
 * Instead, use the non-checking variants.  This is sad.
 *
 * See https://trac.torproject.org/projects/tor/ticket/15205
 */
#undef strlcat
#undef strlcpy
#endif /* defined __APPLE__ */

#ifndef HAVE_STRLCAT
rl1987's avatar
rl1987 committed
44
size_t strlcat(char *dst, const char *src, size_t siz);
45
46
#endif
#ifndef HAVE_STRLCPY
rl1987's avatar
rl1987 committed
47
size_t strlcpy(char *dst, const char *src, size_t siz);
48
49
#endif

50
51
52
53
54
55
56
char *tor_strtok_r_impl(char *str, const char *sep, char **lasts);
#ifdef HAVE_STRTOK_R
#define tor_strtok_r(str, sep, lasts) strtok_r(str, sep, lasts)
#else
#define tor_strtok_r(str, sep, lasts) tor_strtok_r_impl(str, sep, lasts)
#endif

57
#endif