]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
build: require POSIX `strdup()`
authorViktor Szakats <commit@vsz.me>
Mon, 2 Feb 2026 18:02:34 +0000 (19:02 +0100)
committerViktor Szakats <commit@vsz.me>
Tue, 3 Feb 2026 16:50:18 +0000 (17:50 +0100)
Stop detecting this function and drop the local fallback.

Let us know if this update is causing an issue.

Notes:
- on Windows `_strdup()` is required instead.
- `strdup()/_strdup()` were required before this patch to build one of
  the examples: `block_ip`.
- `strdup()/_strdup()` were required in 8.18.0 and earlier to build
  tests.

Closes #20505

CMake/unix-cache.cmake
CMakeLists.txt
configure.ac
lib/config-os400.h
lib/config-riscos.h
lib/curl_config-cmake.h.in
lib/curl_setup.h
lib/curlx/strdup.c
lib/curlx/strdup.h
m4/curl-functions.m4

index fac54cd0fbf1094165fa3a930959a107ff61651d..1c6add8397ea78d8117cfda37f89bb06c81d34c8 100644 (file)
@@ -246,7 +246,6 @@ set(HAVE_STDDEF_H 1)  # detected by CMake internally in check_type_size()
 set(HAVE_STDINT_H 1)  # detected by CMake internally in check_type_size()
 set(HAVE_STRCASECMP 1)
 set(HAVE_STRCMPI 0)
-set(HAVE_STRDUP 1)
 set(HAVE_STRERROR_R 1)
 set(HAVE_STRICMP 0)
 set(HAVE_STRINGS_H 1)
index 2b324e9585bcb1d2a6d18438eafa19a45214d53e..66639198517ebc2f905eb6b2b6b1a5c0417d0dcd 100644 (file)
@@ -1612,7 +1612,6 @@ if(NOT WIN32)
   check_function_exists("realpath"        HAVE_REALPATH)
   check_function_exists("sched_yield"     HAVE_SCHED_YIELD)
   check_symbol_exists("strcasecmp"        "string.h" HAVE_STRCASECMP)
-  check_symbol_exists("strdup"            "string.h" HAVE_STRDUP)
   check_symbol_exists("stricmp"           "string.h" HAVE_STRICMP)
   check_symbol_exists("strcmpi"           "string.h" HAVE_STRCMPI)
 endif()
index f400a02076147a355ad44dae435f24d2b49ca01b..827f5f17a05dc72fbfef43f5cf9b614a5664e61c 100644 (file)
@@ -4204,7 +4204,6 @@ if test "$curl_cv_native_windows" != "yes"; then
   CURL_CHECK_FUNC_INET_PTON
   CURL_CHECK_FUNC_STRCASECMP
   CURL_CHECK_FUNC_STRCMPI
-  CURL_CHECK_FUNC_STRDUP
   CURL_CHECK_FUNC_STRICMP
 fi
 
index 294d512a9f546e3ff5f7f310116cd97101517a13..8071b8ad4effe63bf0feb78dfbefbd76ac159d28 100644 (file)
 /* Define if you have the `stricmp' function. */
 #define HAVE_STRICMP
 
-/* Define if you have the `strdup' function. */
-#define HAVE_STRDUP
-
 /* Define if you have the <strings.h> header file. */
 #define HAVE_STRINGS_H
 
index 43f33e50864f0a0c6df642291e93f1e4fdac542d..9f585565d89a95a8fd141e724d0fb8f0bb3cfae4 100644 (file)
 /* Define if you have the `strcmpi' function. */
 #undef HAVE_STRCMPI
 
-/* Define if you have the `strdup' function. */
-#define HAVE_STRDUP
-
 /* Define if you have the `stricmp' function. */
 #define HAVE_STRICMP
 
index a418b1674832505a8501e1c15a4bed65476e8d47..9f9c60015e95ead23545675df77b8f22c6e4cd49 100644 (file)
 /* Define to 1 if you have the strcmpi function. */
 #cmakedefine HAVE_STRCMPI 1
 
-/* Define to 1 if you have the strdup function. */
-#cmakedefine HAVE_STRDUP 1
-
 /* Define to 1 if you have the strerror_r function. */
 #cmakedefine HAVE_STRERROR_R 1
 
index 6f564eff1eda546a75b55b13c9ccfd5339998a81..10cdb563d11b4ef2b0c3037d13ae91bf7b5d4db2 100644 (file)
@@ -1079,8 +1079,6 @@ CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode,
 
 #ifdef _WIN32
 #define CURLX_STRDUP_LOW _strdup
-#elif !defined(HAVE_STRDUP)
-#define CURLX_STRDUP_LOW curlx_strdup_low
 #else
 #define CURLX_STRDUP_LOW strdup
 #endif
index 59031bcf13e2da709140e9cfc0e14132d730b664..75e088fe4ce605e7ce7f0706265533caecae2ebc 100644 (file)
@@ -49,24 +49,6 @@ wchar_t *curlx_wcsdup(const wchar_t *src)
 
   return (wchar_t *)curlx_memdup(src, (length + 1) * sizeof(wchar_t));
 }
-#elif !defined(HAVE_STRDUP)
-char *curlx_strdup_low(const char *str)
-{
-  size_t len;
-  char *newstr;
-
-  if(!str)
-    return NULL;
-
-  len = strlen(str) + 1;
-
-  newstr = curlx_malloc(len);
-  if(!newstr)
-    return NULL;
-
-  memcpy(newstr, str, len);
-  return newstr;
-}
 #endif
 
 /***************************************************************************
index eac4039b38b5664405455cafc68678a550cc1c5d..1e6bc1981429b9e4055bccd0448e9256a4dd1b41 100644 (file)
@@ -27,8 +27,6 @@
 
 #ifdef _WIN32
 wchar_t *curlx_wcsdup(const wchar_t *src);  /* for curlx_tcsdup() */
-#elif !defined(HAVE_STRDUP)
-char *curlx_strdup_low(const char *str);
 #endif
 void *curlx_memdup(const void *src, size_t buffer_length);
 void *curlx_memdup0(const char *src, size_t length);
index 52885d84a84cb6d20266a615e4815d5ccb8eef6e..f4fbe3ad78bc08ad2bd0ab9a1beb66fda3f6b5f4 100644 (file)
@@ -3935,92 +3935,6 @@ AC_DEFUN([CURL_CHECK_FUNC_STRCMPI], [
 ])
 
 
-dnl CURL_CHECK_FUNC_STRDUP
-dnl -------------------------------------------------
-dnl Verify if strdup is available, prototyped, and
-dnl can be compiled. If all of these are true, and
-dnl usage has not been previously disallowed with
-dnl shell variable curl_disallow_strdup, then
-dnl HAVE_STRDUP will be defined.
-
-AC_DEFUN([CURL_CHECK_FUNC_STRDUP], [
-  AC_REQUIRE([CURL_INCLUDES_STRING])dnl
-  AC_REQUIRE([CURL_INCLUDES_STDLIB])dnl
-  #
-  tst_links_strdup="unknown"
-  tst_proto_strdup="unknown"
-  tst_compi_strdup="unknown"
-  tst_allow_strdup="unknown"
-  #
-  AC_MSG_CHECKING([if strdup can be linked])
-  AC_LINK_IFELSE([
-    AC_LANG_FUNC_LINK_TRY([strdup])
-  ],[
-    AC_MSG_RESULT([yes])
-    tst_links_strdup="yes"
-  ],[
-    AC_MSG_RESULT([no])
-    tst_links_strdup="no"
-  ])
-  #
-  if test "$tst_links_strdup" = "yes"; then
-    AC_MSG_CHECKING([if strdup is prototyped])
-    AC_EGREP_CPP([strdup],[
-      $curl_includes_string
-    ],[
-      AC_MSG_RESULT([yes])
-      tst_proto_strdup="yes"
-    ],[
-      AC_MSG_RESULT([no])
-      tst_proto_strdup="no"
-    ])
-  fi
-  #
-  if test "$tst_proto_strdup" = "yes"; then
-    AC_MSG_CHECKING([if strdup is compilable])
-    AC_COMPILE_IFELSE([
-      AC_LANG_PROGRAM([[
-        $curl_includes_string
-        $curl_includes_stdlib
-      ]],[[
-        free(strdup(""));
-      ]])
-    ],[
-      AC_MSG_RESULT([yes])
-      tst_compi_strdup="yes"
-    ],[
-      AC_MSG_RESULT([no])
-      tst_compi_strdup="no"
-    ])
-  fi
-  #
-  if test "$tst_compi_strdup" = "yes"; then
-    AC_MSG_CHECKING([if strdup usage allowed])
-    if test "x$curl_disallow_strdup" != "xyes"; then
-      AC_MSG_RESULT([yes])
-      tst_allow_strdup="yes"
-    else
-      AC_MSG_RESULT([no])
-      tst_allow_strdup="no"
-    fi
-  fi
-  #
-  AC_MSG_CHECKING([if strdup might be used])
-  if test "$tst_links_strdup" = "yes" &&
-     test "$tst_proto_strdup" = "yes" &&
-     test "$tst_compi_strdup" = "yes" &&
-     test "$tst_allow_strdup" = "yes"; then
-    AC_MSG_RESULT([yes])
-    AC_DEFINE_UNQUOTED(HAVE_STRDUP, 1,
-      [Define to 1 if you have the strdup function.])
-    curl_cv_func_strdup="yes"
-  else
-    AC_MSG_RESULT([no])
-    curl_cv_func_strdup="no"
-  fi
-])
-
-
 dnl CURL_CHECK_FUNC_STRERROR_R
 dnl -------------------------------------------------
 dnl Verify if strerror_r is available, prototyped, can be compiled and