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:
parent
68bd759c2b
commit
6dacd2f208
@ -36,7 +36,6 @@ if(MINGW)
|
||||
set(HAVE_BOOL_T "${HAVE_STDBOOL_H}")
|
||||
set(HAVE_STRTOLL 1)
|
||||
set(HAVE_BASENAME 1)
|
||||
set(HAVE_STRCASECMP 1)
|
||||
set(HAVE_FTRUNCATE 1)
|
||||
set(HAVE_SYS_PARAM_H 1)
|
||||
set(HAVE_SYS_TIME_H 1)
|
||||
@ -47,7 +46,6 @@ if(MINGW)
|
||||
set(HAVE_OPENDIR 1)
|
||||
else()
|
||||
set(HAVE_LIBGEN_H 0)
|
||||
set(HAVE_STRCASECMP 0)
|
||||
set(HAVE_FTRUNCATE 0)
|
||||
set(HAVE_SYS_PARAM_H 0)
|
||||
set(HAVE_SYS_TIME_H 0)
|
||||
@ -149,8 +147,6 @@ set(HAVE_FSEEKO 0) # mingw-w64 2.0.0 and newer has it
|
||||
set(HAVE_SOCKET 1)
|
||||
set(HAVE_SELECT 1)
|
||||
set(HAVE_STRDUP 1)
|
||||
set(HAVE_STRICMP 1)
|
||||
set(HAVE_STRCMPI 1)
|
||||
set(HAVE_MEMRCHR 0)
|
||||
set(HAVE_CLOSESOCKET 1)
|
||||
set(HAVE_SIGSETJMP 0)
|
||||
|
||||
@ -1631,9 +1631,6 @@ check_function_exists("sendmmsg" HAVE_SENDMMSG)
|
||||
check_symbol_exists("select" "${CURL_INCLUDES}" HAVE_SELECT) # proto/bsdsocket.h sys/select.h sys/socket.h
|
||||
check_symbol_exists("strdup" "string.h" HAVE_STRDUP)
|
||||
check_symbol_exists("strtok_r" "string.h" HAVE_STRTOK_R)
|
||||
check_symbol_exists("strcasecmp" "string.h" HAVE_STRCASECMP)
|
||||
check_symbol_exists("stricmp" "string.h" HAVE_STRICMP)
|
||||
check_symbol_exists("strcmpi" "string.h" HAVE_STRCMPI)
|
||||
check_symbol_exists("memrchr" "string.h" HAVE_MEMRCHR)
|
||||
check_symbol_exists("alarm" "unistd.h" HAVE_ALARM)
|
||||
check_symbol_exists("fcntl" "fcntl.h" HAVE_FCNTL)
|
||||
@ -1672,6 +1669,12 @@ check_function_exists("setlocale" HAVE_SETLOCALE)
|
||||
check_function_exists("setmode" HAVE_SETMODE)
|
||||
check_function_exists("setrlimit" HAVE_SETRLIMIT)
|
||||
|
||||
if(NOT WIN32)
|
||||
check_symbol_exists("strcasecmp" "string.h" HAVE_STRCASECMP)
|
||||
check_symbol_exists("stricmp" "string.h" HAVE_STRICMP)
|
||||
check_symbol_exists("strcmpi" "string.h" HAVE_STRCMPI)
|
||||
endif()
|
||||
|
||||
if(WIN32 OR CYGWIN)
|
||||
check_function_exists("_setmode" HAVE__SETMODE)
|
||||
endif()
|
||||
|
||||
@ -4021,11 +4021,8 @@ CURL_CHECK_FUNC_SIGNAL
|
||||
CURL_CHECK_FUNC_SIGSETJMP
|
||||
CURL_CHECK_FUNC_SOCKET
|
||||
CURL_CHECK_FUNC_SOCKETPAIR
|
||||
CURL_CHECK_FUNC_STRCASECMP
|
||||
CURL_CHECK_FUNC_STRCMPI
|
||||
CURL_CHECK_FUNC_STRDUP
|
||||
CURL_CHECK_FUNC_STRERROR_R
|
||||
CURL_CHECK_FUNC_STRICMP
|
||||
CURL_CHECK_FUNC_STRTOK_R
|
||||
CURL_CHECK_FUNC_STRTOLL
|
||||
|
||||
@ -4066,6 +4063,12 @@ AC_CHECK_FUNCS([\
|
||||
utimes \
|
||||
])
|
||||
|
||||
if test "$curl_cv_native_windows" != 'yes'; then
|
||||
CURL_CHECK_FUNC_STRCASECMP
|
||||
CURL_CHECK_FUNC_STRCMPI
|
||||
CURL_CHECK_FUNC_STRICMP
|
||||
fi
|
||||
|
||||
if test "$curl_cv_native_windows" = 'yes' -o "$curl_cv_cygwin" = 'yes'; then
|
||||
AC_CHECK_FUNCS([_setmode])
|
||||
fi
|
||||
|
||||
@ -158,17 +158,9 @@
|
||||
/* Define if you have the socket function. */
|
||||
#define HAVE_SOCKET 1
|
||||
|
||||
/* Define if you have the strcasecmp function. */
|
||||
#if defined(__MINGW32__)
|
||||
#define HAVE_STRCASECMP 1
|
||||
#endif
|
||||
|
||||
/* Define if you have the strdup function. */
|
||||
#define HAVE_STRDUP 1
|
||||
|
||||
/* Define if you have the stricmp function. */
|
||||
#define HAVE_STRICMP 1
|
||||
|
||||
/* Define if you have the strtoll function. */
|
||||
#if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || defined(__MINGW32__)
|
||||
#define HAVE_STRTOLL 1
|
||||
|
||||
@ -114,15 +114,9 @@
|
||||
/* Define if you have the socket function. */
|
||||
#define HAVE_SOCKET 1
|
||||
|
||||
/* Define if you have the strcasecmp function. */
|
||||
/* #define HAVE_STRCASECMP 1 */
|
||||
|
||||
/* Define if you have the strdup function. */
|
||||
/* #define HAVE_STRDUP 1 */
|
||||
|
||||
/* Define if you have the stricmp function. */
|
||||
/* #define HAVE_STRICMP 1 */
|
||||
|
||||
/* Define if you have the strtoll function. */
|
||||
#if defined(__MINGW32__)
|
||||
#define HAVE_STRTOLL 1
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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. */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user