Wed, 01 Jan 2025 15:48:48 +0100
fix for ultrafail fix #546
src/string.c | file | annotate | diff | comparison | revisions |
--- a/src/string.c Wed Jan 01 15:33:41 2025 +0100 +++ b/src/string.c Wed Jan 01 15:48:48 2025 +0100 @@ -36,11 +36,12 @@ #include <limits.h> #include <float.h> -#ifndef _WIN32 - -#include <strings.h> // for strncasecmp() - -#endif // _WIN32 +#ifdef _WIN32 +#define cx_strcasecmp_impl _strnicmp +#else +#include <strings.h> +#define cx_strcasecmp_impl strncasecmp +#endif cxmutstr cx_mutstr(char *cstring) { return (cxmutstr) {cstring, strlen(cstring)}; @@ -463,13 +464,15 @@ cxstring s1, cxstring s2 ) { - int r = strncmp(s1.ptr, s2.ptr, s1.length); - if (r != 0) return r; if (s1.length == s2.length) { - return 0; + return strncmp(s1.ptr, s2.ptr, s1.length); } else if (s1.length > s2.length) { + int r = strncmp(s1.ptr, s2.ptr, s2.length); + if (r != 0) return r; return 1; } else { + int r = strncmp(s1.ptr, s2.ptr, s1.length); + if (r != 0) return r; return -1; } } @@ -478,17 +481,15 @@ cxstring s1, cxstring s2 ) { -#ifdef _WIN32 - int r = _strnicmp(s1.ptr, s2.ptr, s1.length); -#else - int r = strncasecmp(s1.ptr, s2.ptr, s1.length); -#endif - if (r != 0) return r; if (s1.length == s2.length) { - return 0; + return cx_strcasecmp_impl(s1.ptr, s2.ptr, s1.length); } else if (s1.length > s2.length) { + int r = cx_strcasecmp_impl(s1.ptr, s2.ptr, s2.length); + if (r != 0) return r; return 1; } else { + int r = cx_strcasecmp_impl(s1.ptr, s2.ptr, s1.length); + if (r != 0) return r; return -1; } }