]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
src: add `CURL_STRICMP()` macro, use `_stricmp()` on Windows
authorViktor Szakats <commit@vsz.me>
Wed, 27 Nov 2024 11:34:38 +0000 (12:34 +0100)
committerViktor Szakats <commit@vsz.me>
Mon, 23 Dec 2024 21:06:07 +0000 (22:06 +0100)
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

CMake/Platforms/WindowsCache.cmake
CMakeLists.txt
configure.ac
lib/config-win32.h
lib/config-win32ce.h
src/tool_setup.h
src/tool_util.c

index 175a8b0be850c911e4cdd057faa00988e4413889..f5dea6aacc967e6d5af8ac1df2c65bd1b54e3a37 100644 (file)
@@ -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)
index 964be8b2d952c3b4d7fe68a6d97b9ac4c9d5f4e8..d60a77100b0de27bbe88d6c98a2a0310e42a2995 100644 (file)
@@ -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()
index d1e87f101a535fff0f5b94bad2bef11ef44222db..e1c06aff81b46b95dd435c22a7207c8cf2bfda50 100644 (file)
@@ -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
index cc4d5cb3df5259a4c6acab88cdf7fc7a446adb26..1f280a96c6c2f4193985234deab9b4572b5cf839 100644 (file)
 /* 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
index ba801110adfce562c3131f9798ae884cc4458687..492d74350c24768dac9b7cb978bc0f897cec26a2 100644 (file)
 /* 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
index 82eb6e5a0b570765f4e8a874f80d4352a5424f8e..8c89e60275978344d74ceb6cba8a554730d2eca7 100644 (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;
index 69b1d2b42acc7ea16a4e24769c61b860ea915444..8a078890d4d449621c5781c5f2544408f9891a7d 100644 (file)
  ***************************************************************************/
 #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. */