]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
windows: use `_strdup()` instead of `strdup()` where missing
authorViktor Szakats <commit@vsz.me>
Mon, 1 Dec 2025 18:49:50 +0000 (19:49 +0100)
committerViktor Szakats <commit@vsz.me>
Mon, 1 Dec 2025 20:32:09 +0000 (21:32 +0100)
To replace deprecated `strdup()` CRT calls with the recommended
`_strdup()`.

Refs:
https://learn.microsoft.com/cpp/c-runtime-library/reference/strdup-wcsdup
https://learn.microsoft.com/cpp/c-runtime-library/reference/strdup-wcsdup-mbsdup

Closes #19794

docs/examples/block_ip.c
lib/curl_setup.h
lib/easy.c
tests/libtest/memptr.c
tests/server/first.h

index bf2193a26359a11e2ac3970c4f5f44a565414f4d..5cd77cad0e806c9a3b536fffb06b4d0cbb5eaab3 100644 (file)
@@ -38,12 +38,6 @@ int main(void)
 }
 #else
 
-#ifdef _MSC_VER
-#ifndef _CRT_NONSTDC_NO_DEPRECATE
-#define _CRT_NONSTDC_NO_DEPRECATE  /* for strdup() */
-#endif
-#endif
-
 #ifdef _WIN32
 #if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0600
 #undef _WIN32_WINNT
@@ -52,6 +46,7 @@ int main(void)
 #include <winsock2.h>
 #include <ws2tcpip.h>
 #include <windows.h>
+#define strdup _strdup
 #else
 #include <sys/types.h>
 #include <sys/socket.h>
index 6acac0d17ad0debf3ea2b1806956ce2eb10caea9..2cc18cf414881231095c6e63893435810c692e82 100644 (file)
@@ -91,8 +91,7 @@
 #pragma warning(disable:4127)
 /* Avoid VS2005 and upper complaining about portable C functions. */
 #ifndef _CRT_NONSTDC_NO_DEPRECATE  /* mingw-w64 v2+. MS SDK ~10+/~VS2017+. */
-#define _CRT_NONSTDC_NO_DEPRECATE  /* for close(), fileno(), strdup(),
-                                      unlink(), etc. */
+#define _CRT_NONSTDC_NO_DEPRECATE  /* for close(), fileno(), unlink(), etc. */
 #endif
 #ifndef _CRT_SECURE_NO_WARNINGS
 #define _CRT_SECURE_NO_WARNINGS  /* for getenv(), gmtime(), strcpy(),
index 476f63c74dff58723af1e74decc73f46960a2bc2..c60819fcdc6e31a87b3ed6b353b9a0f01d58f79a 100644 (file)
@@ -103,7 +103,11 @@ static curl_simple_lock s_lock = CURL_SIMPLE_LOCK_INIT;
  * so the callback pointer is initialized correctly.
  */
 #ifdef HAVE_STRDUP
+#ifdef _WIN32
+#define system_strdup _strdup
+#else
 #define system_strdup strdup
+#endif
 #else
 #define system_strdup Curl_strdup
 #endif
index 400e72c41ab94d964d500f8ae8c28e06ec0cbefb..fe90b01a6cb1e42b33c3f06447f9c984cd1ca880 100644 (file)
 curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
 curl_free_callback Curl_cfree = (curl_free_callback)free;
 curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
+#ifdef _WIN32
+curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)_strdup;
+#else
 curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)strdup;
+#endif
 curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
 
 #if defined(_MSC_VER) && defined(_DLL)
index 2979239ad3662bb02baed48816f597d9f124cdb7..316a7a622e8dfc77bec18b70e043283a4f1b2382 100644 (file)
@@ -69,6 +69,10 @@ extern const struct entry_s s_entries[];
 #  define snprintf _snprintf
 #endif
 
+#ifdef _WIN32
+#  define strdup _strdup
+#endif
+
 #ifdef _WIN32
 #  define CURL_STRNICMP(p1, p2, n) _strnicmp(p1, p2, n)
 #elif defined(HAVE_STRCASECMP)