1 /*
2  * Public domain
3  * string.h compatibility shim
4  */
5 
6 #ifndef LIBCRYPTOCOMPAT_STRING_H
BOOST_AUTO_TEST_SUITE(compilerbug_tests)7 #define LIBCRYPTOCOMPAT_STRING_H
8 
9 #ifdef _MSC_VER
10 #if _MSC_VER >= 1900
11 #include <../ucrt/string.h>
12 #else
13 #include <../include/string.h>
14 #endif
15 #else
16 #include_next <string.h>
17 #endif
18 
19 #include <sys/types.h>
20 
21 #if defined(__sun) || defined(_AIX) || defined(__hpux)
22 /* Some functions historically defined in string.h were placed in strings.h by
23  * SUS. Use the same hack as OS X and FreeBSD use to work around on AIX,
24  * Solaris, and HPUX.
25  */
26 #include <strings.h>
27 #endif
28 
29 #ifndef HAVE_STRCASECMP
30 int strcasecmp(const char *s1, const char *s2);
31 int strncasecmp(const char *s1, const char *s2, size_t len);
32 #endif
33 
34 #ifndef HAVE_STRLCPY
35 size_t strlcpy(char *dst, const char *src, size_t siz);
36 #endif
37 
38 #ifndef HAVE_STRLCAT
39 size_t strlcat(char *dst, const char *src, size_t siz);
40 #endif
41 
42 #ifndef HAVE_STRNDUP
43 char * strndup(const char *str, size_t maxlen);
44 /* the only user of strnlen is strndup, so only build it if needed */
45 #ifndef HAVE_STRNLEN
46 size_t strnlen(const char *str, size_t maxlen);
47 #endif
48 #endif
49 
50 #ifndef HAVE_STRSEP
51 char *strsep(char **stringp, const char *delim);
52 #endif
53 
54 #ifndef HAVE_EXPLICIT_BZERO
55 void explicit_bzero(void *, size_t);
56 #endif
57 
58 #ifndef HAVE_TIMINGSAFE_BCMP
59 int timingsafe_bcmp(const void *b1, const void *b2, size_t n);
60 #endif
61 
62 #ifndef HAVE_TIMINGSAFE_MEMCMP
63 int timingsafe_memcmp(const void *b1, const void *b2, size_t len);
64 #endif
65 
66 #ifndef HAVE_MEMMEM
67 void * memmem(const void *big, size_t big_len, const void *little,
68 	size_t little_len);
69 #endif
70 
71 #ifdef _WIN32
72 #include <errno.h>
73 
74 static inline char  *
75 posix_strerror(int errnum)
76 {
77 	if (errnum == ECONNREFUSED) {
78 		return "Connection refused";
79 	}
80 	return strerror(errnum);
81 }
82 
83 #define strerror(errnum) posix_strerror(errnum)
84 
85 #endif
86 
87 #endif
88