|
6 | 6 | #ifndef LIBACQUIRE_ACQUIRE_STRING_EXTRAS_H |
7 | 7 | #define LIBACQUIRE_ACQUIRE_STRING_EXTRAS_H |
8 | 8 |
|
| 9 | +#include <string.h> |
| 10 | + |
| 11 | +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ |
| 12 | + defined(__bsdi__) || defined(__DragonFly__) || defined(BSD) |
| 13 | +# define ANY_BSD |
| 14 | +#endif |
| 15 | + |
9 | 16 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) |
10 | 17 |
|
11 | 18 | # if defined(_MSC_VER) && !defined(__INTEL_COMPILER) |
12 | 19 |
|
| 20 | + /* snprintf is implemented in VS 2015 */ |
13 | 21 | # if _MSC_VER >= 1900 |
14 | 22 |
|
15 | | -/* snprintf is implemented in VS 2015 */ |
| 23 | + |
16 | 24 | # define HAVE_SNPRINTF_H |
17 | 25 |
|
18 | 26 | # endif /* _MSC_VER >= 1900 */ |
|
27 | 35 |
|
28 | 36 | # include <sys/param.h> |
29 | 37 |
|
30 | | -# if _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L || \ |
31 | | - defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || \ |
32 | | - defined(__DragonFly__) || defined(BSD) |
| 38 | +# if _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L || defined(ANY_BSD) |
33 | 39 | # define HAVE_SNPRINTF_H |
34 | 40 | # define HAVE_STRCASESTR_H |
35 | | -# endif /* _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L */ |
| 41 | +# endif /* _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L || defined(ANY_BSD) */ |
36 | 42 |
|
37 | 43 | # if defined(__APPLE__) && defined(__MACH__) |
38 | 44 | # define HAVE_SNPRINTF_H |
39 | 45 | # define HAVE_STRNCASECMP_H |
40 | 46 | # endif /* defined(__APPLE__) && defined(__MACH__) */ |
41 | 47 |
|
42 | | -# if (defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L) || defined(BSD) && (BSD >= 199306)) && \ |
43 | | - (!defined(__linux__) && !defined(linux) && !defined(__linux)) |
44 | | -# define HAVE_STRNSTR_H |
45 | | -# endif /* (defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L) || defined(BSD) && (BSD >= 199306)) && \ |
46 | | - (!defined(__linux__) && !defined(linux) && !defined(__linux)) */ |
| 48 | +# if defined(BSD) && (BSD >= 199306) && !defined(__linux__) && !defined(linux) && !defined(__linux) |
| 49 | +# define HAVE_STRNSTR |
| 50 | +# endif /* defined(BSD) && (BSD >= 199306) && !defined(__linux__) && !defined(linux) && !defined(__linux) */ |
47 | 51 |
|
48 | 52 | #endif /* defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) */ |
49 | 53 |
|
|
66 | 70 | # define HAVE_STRNCASECMP_H |
67 | 71 | #endif |
68 | 72 |
|
| 73 | +#if defined(ANY_BSD) || defined(__APPLE__) && defined(__MACH__) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 74 | +# define HAVE_ASPRINTF |
| 75 | +#endif /* defined(ANY_BSD) || defined(__APPLE__) && defined(__MACH__) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) */ |
| 76 | + |
69 | 77 | #include <stdarg.h> |
70 | 78 | #include <stdio.h> |
71 | 79 | #include <string.h> |
|
77 | 85 | #if !defined(HAVE_SNPRINTF_H) && defined(LIBACQUIRE_IMPLEMENTATION) |
78 | 86 |
|
79 | 87 | /* |
80 | | - * `snprintf`, `strncasecmp`, `vsnprintf`, `strnstr` taken from: |
| 88 | + * `snprintf`, `vsnprintf`, `strnstr` taken from: |
81 | 89 | * https://chromium.googlesource.com/chromium/blink/+/5cedd2fd208daf119b9ea47c7c1e22d760a586eb/Source/wtf/StringExtras.h |
82 | 90 | * …then modified to remove C++ specifics and WebKit specific macros |
83 | 91 | * |
@@ -126,19 +134,15 @@ extern int strcasecmp(const char *, const char *); |
126 | 134 |
|
127 | 135 | #ifdef LIBACQUIRE_IMPLEMENTATION |
128 | 136 |
|
129 | | -int strncasecmp(const char *s1, const char *s2, size_t len) { |
130 | | - return _strnicmp(s1, s2, len); |
131 | | -} |
| 137 | +#define strncasecmp _strnicmp |
132 | 138 |
|
133 | | -int strcasecmp(const char *s1, const char *s2) { |
134 | | - return _stricmp(s1, s2); |
135 | | -} |
| 139 | +#define strcasecmp _stricmp |
136 | 140 |
|
137 | 141 | #endif /* LIBACQUIRE_IMPLEMENTATION */ |
138 | 142 |
|
139 | 143 | #endif /* !HAVE_STRNCASECMP_H */ |
140 | 144 |
|
141 | | -#ifndef HAVE_STRNSTR_H |
| 145 | +#ifndef HAVE_STRNSTR |
142 | 146 |
|
143 | 147 | extern char *strnstr(const char *, const char *, size_t); |
144 | 148 |
|
@@ -172,7 +176,7 @@ char *strnstr(const char *buffer, const char *target, size_t bufferLength) { |
172 | 176 | } |
173 | 177 | #endif /* LIBACQUIRE_IMPLEMENTATION */ |
174 | 178 |
|
175 | | -#endif /* ! HAVE_STRNSTR_H */ |
| 179 | +#endif /* ! HAVE_STRNSTR */ |
176 | 180 |
|
177 | 181 | #ifndef HAVE_STRCASESTR_H |
178 | 182 | extern char *strcasestr(const char *, const char *); |
@@ -242,6 +246,6 @@ size_t strerrorlen_s(errno_t errnum) |
242 | 246 | } |
243 | 247 | } |
244 | 248 |
|
245 | | -#endif /* HAVE_STRERRORLEN_S */ |
| 249 | +#endif /* !HAVE_STRERRORLEN_S */ |
246 | 250 |
|
247 | 251 | #endif /* ! LIBACQUIRE_ACQUIRE_STRING_EXTRAS_H */ |
0 commit comments