diff options
author | Brent Cook <busterb@gmail.com> | 2014-07-10 22:06:10 -0500 |
---|---|---|
committer | Brent Cook <bcook@openbsd.org> | 2015-07-21 12:08:18 -0500 |
commit | 5d8a1cf7155130bd8101090d7e1d0c2f90d9b123 (patch) | |
tree | 286f7d12e3647f94bd1e6e8e180a4bf6215a0740 /include/compat/string.h | |
parent | 7a4a37cf596697ae96eeb1c555989e6d1a443187 (diff) | |
download | portable-5d8a1cf7155130bd8101090d7e1d0c2f90d9b123.tar.gz portable-5d8a1cf7155130bd8101090d7e1d0c2f90d9b123.tar.bz2 portable-5d8a1cf7155130bd8101090d7e1d0c2f90d9b123.zip |
add initial CMake and Visual Studio build support
This moves the compatibility include files from include to
include/compat so we can use the awful MS C compiler
<../include/> trick to emulate the GNU #include_next extension.
This also removes a few old compat files we do not need anymore.
Diffstat (limited to 'include/compat/string.h')
-rw-r--r-- | include/compat/string.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/include/compat/string.h b/include/compat/string.h new file mode 100644 index 0000000..eabc4c4 --- /dev/null +++ b/include/compat/string.h | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | * Public domain | ||
3 | * string.h compatibility shim | ||
4 | */ | ||
5 | |||
6 | #ifndef LIBCRYPTOCOMPAT_STRING_H | ||
7 | #define LIBCRYPTOCOMPAT_STRING_H | ||
8 | |||
9 | #ifdef _MSC_VER | ||
10 | #include <../include/string.h> | ||
11 | #else | ||
12 | #include_next <string.h> | ||
13 | #endif | ||
14 | |||
15 | #include <sys/types.h> | ||
16 | |||
17 | #if defined(__sun) || defined(__hpux) | ||
18 | /* Some functions historically defined in string.h were placed in strings.h by | ||
19 | * SUS. Use the same hack as OS X and FreeBSD use to work around on Solaris and HPUX. | ||
20 | */ | ||
21 | #include <strings.h> | ||
22 | #endif | ||
23 | |||
24 | #ifndef HAVE_STRCASECMP | ||
25 | int strcasecmp(const char *s1, const char *s2); | ||
26 | int strncasecmp(const char *s1, const char *s2, size_t len); | ||
27 | #endif | ||
28 | |||
29 | #ifndef HAVE_STRLCPY | ||
30 | size_t strlcpy(char *dst, const char *src, size_t siz); | ||
31 | #endif | ||
32 | |||
33 | #ifndef HAVE_STRLCAT | ||
34 | size_t strlcat(char *dst, const char *src, size_t siz); | ||
35 | #endif | ||
36 | |||
37 | #ifndef HAVE_STRNDUP | ||
38 | char * strndup(const char *str, size_t maxlen); | ||
39 | /* the only user of strnlen is strndup, so only build it if needed */ | ||
40 | #ifndef HAVE_STRNLEN | ||
41 | size_t strnlen(const char *str, size_t maxlen); | ||
42 | #endif | ||
43 | #endif | ||
44 | |||
45 | #ifndef HAVE_STRSEP | ||
46 | char *strsep(char **stringp, const char *delim); | ||
47 | #endif | ||
48 | |||
49 | #ifndef HAVE_EXPLICIT_BZERO | ||
50 | void explicit_bzero(void *, size_t); | ||
51 | #endif | ||
52 | |||
53 | #ifndef HAVE_TIMINGSAFE_BCMP | ||
54 | int timingsafe_bcmp(const void *b1, const void *b2, size_t n); | ||
55 | #endif | ||
56 | |||
57 | #ifndef HAVE_TIMINGSAFE_MEMCMP | ||
58 | int timingsafe_memcmp(const void *b1, const void *b2, size_t len); | ||
59 | #endif | ||
60 | |||
61 | #ifndef HAVE_MEMMEM | ||
62 | void * memmem(const void *big, size_t big_len, const void *little, | ||
63 | size_t little_len); | ||
64 | #endif | ||
65 | |||
66 | #ifdef _WIN32 | ||
67 | #include <errno.h> | ||
68 | |||
69 | static inline char * | ||
70 | posix_strerror(int errnum) | ||
71 | { | ||
72 | if (errnum == ECONNREFUSED) { | ||
73 | return "Connection refused"; | ||
74 | } | ||
75 | return strerror(errnum); | ||
76 | } | ||
77 | |||
78 | #define strerror(errnum) posix_strerror(errnum) | ||
79 | |||
80 | #endif | ||
81 | |||
82 | #endif | ||