src: add CURL_STRICMP() macro, use _stricmp() on Windows

Add `CURL_STRICMP()` macro that works on all platforms depending on
which lib C function is available.

Make sure to always use `_stricmp()` on Windows, which is the
non-deprecated, official API for this on this platform. Before this
patch it used a MinGW-specific call, or a deprecated compatibility
wrapper with MSVC.

Drop `stricmp` variant detections on Windows with autotools.

https://learn.microsoft.com/cpp/c-runtime-library/reference/stricmp-wcsicmp-mbsicmp-stricmp-l-wcsicmp-l-mbsicmp-l

Ref: #15652
Closes #15788
This commit is contained in:
Viktor Szakats 2024-11-27 12:34:38 +01:00
parent 68bd759c2b
commit 6dacd2f208
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
7 changed files with 28 additions and 37 deletions

View file

@ -66,6 +66,21 @@ extern FILE *tool_stderr;
# include "tool_strdup.h"
#endif
#if defined(_WIN32)
# define CURL_STRICMP(p1, p2) _stricmp(p1, p2)
#elif defined(HAVE_STRCASECMP)
# ifdef HAVE_STRINGS_H
# include <strings.h>
# endif
# define CURL_STRICMP(p1, p2) strcasecmp(p1, p2)
#elif defined(HAVE_STRCMPI)
# define CURL_STRICMP(p1, p2) strcmpi(p1, p2)
#elif defined(HAVE_STRICMP)
# define CURL_STRICMP(p1, p2) stricmp(p1, p2)
#else
# define CURL_STRICMP(p1, p2) strcmp(p1, p2)
#endif
#if defined(_WIN32)
/* set in win32_init() */
extern LARGE_INTEGER tool_freq;

View file

@ -23,10 +23,6 @@
***************************************************************************/
#include "tool_setup.h"
#if defined(HAVE_STRCASECMP) && defined(HAVE_STRINGS_H)
#include <strings.h>
#endif
#include "tool_util.h"
#include "curlx.h"
@ -181,15 +177,7 @@ int struplocompare(const char *p1, const char *p2)
return p2 ? -1 : 0;
if(!p2)
return 1;
#ifdef HAVE_STRCASECMP
return strcasecmp(p1, p2);
#elif defined(HAVE_STRCMPI)
return strcmpi(p1, p2);
#elif defined(HAVE_STRICMP)
return stricmp(p1, p2);
#else
return strcmp(p1, p2);
#endif
return CURL_STRICMP(p1, p2);
}
/* Indirect version to use as qsort callback. */