@@ -12,6 +12,7 @@ extern "C" {
1212
1313#include <stdarg.h>
1414#include <stdio.h>
15+ #include <ctype.h>
1516#ifdef HAVE_LIBBSD
1617#include <bsd/string.h>
1718#else
@@ -57,7 +58,7 @@ extern "C" {
5758
5859#if defined(__APPLE__ ) && defined(__MACH__ )
5960#define HAVE_SNPRINTF_H
60- #define HAVE_STRNCASECMP_H
61+ #define HAVE_STRNCASECMP
6162#endif /* defined(__APPLE__) && defined(__MACH__) */
6263
6364#if defined(BSD ) && (BSD >= 199306 ) && !defined(__linux__ ) && \
@@ -89,7 +90,7 @@ typedef int errno_t;
8990
9091#ifndef _MSC_VER
9192#define HAVE_STRINGS_H
92- #define HAVE_STRNCASECMP_H
93+ #define HAVE_STRNCASECMP
9394#endif
9495
9596#if defined(ANY_BSD ) || defined(__APPLE__ ) && defined(__MACH__ ) || \
@@ -146,7 +147,7 @@ inline double wtf_vsnprintf(char *buffer, size_t count, const char *format,
146147
147148#endif /* !defined(HAVE_SNPRINTF_H) && defined(LIBACQUIRE_IMPLEMENTATION) */
148149
149- #ifndef HAVE_STRNCASECMP_H
150+ #ifndef HAVE_STRNCASECMP
150151
151152extern LIBACQUIRE_LIB_EXPORT int strncasecmp (const char * , const char * ,
152153 size_t );
@@ -155,13 +156,24 @@ extern LIBACQUIRE_LIB_EXPORT int strcasecmp(const char *, const char *);
155156
156157#ifdef LIBACQUIRE_IMPLEMENTATION
157158
159+ #if defined(_MSC_VER ) && !defined(__INTEL_COMPILER )
158160#define strncasecmp _strnicmp
159161
160162#define strcasecmp _stricmp
163+ #else
164+ /* from MIT licensed musl @ e0ef93c20de1a9e0a6b8f4a4a951a8e61a1a2973 */
165+ int strncasecmp (const char * _l , const char * _r , size_t n )
166+ {
167+ const unsigned char * l = (void * )_l , * r = (void * )_r ;
168+ if (!n -- ) return 0 ;
169+ for (; * l && * r && n && (* l == * r || tolower (* l ) == tolower (* r )); l ++ , r ++ , n -- );
170+ return tolower (* l ) - tolower (* r );
171+ }
172+ #endif /* defined(_MSC_VER) && !defined(__INTEL_COMPILER) */
161173
162174#endif /* LIBACQUIRE_IMPLEMENTATION */
163175
164- #endif /* !HAVE_STRNCASECMP_H */
176+ #endif /* !HAVE_STRNCASECMP */
165177
166178#ifndef HAVE_STRNSTR
167179
0 commit comments