build: require POSIX strdup()

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
This commit is contained in:
Viktor Szakats 2026-02-02 19:02:34 +01:00
parent 710d5a28fb
commit 0590753a3c
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
10 changed files with 0 additions and 120 deletions

View 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)

View 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()

View 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

View file

@ -148,9 +148,6 @@
/* 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

View file

@ -129,9 +129,6 @@
/* 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

View file

@ -535,9 +535,6 @@
/* 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

View 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

View 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
/***************************************************************************

View 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);

View 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