strnlen() is now required
authorPeter Eisentraut <peter@eisentraut.org>
Thu, 8 Jan 2026 07:45:59 +0000 (08:45 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Thu, 8 Jan 2026 07:51:20 +0000 (08:51 +0100)
Remove all configure checks and workarounds for strnlen() missing.  It
is required by POSIX 2008.

Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/98ce805c-6103-421b-adc3-fcf8f3dddbe3%40eisentraut.org

configure
configure.ac
meson.build
src/include/pg_config.h.in
src/include/port.h
src/port/meson.build
src/port/strnlen.c [deleted file]

index 02e4ec7890f142955c74a3cfa00864c19fbcf402..045c913865d8c85fae1a65845ee2d07b7c6db1f2 100755 (executable)
--- a/configure
+++ b/configure
 cat >>confdefs.h <<_ACEOF
 #define HAVE_DECL_STRLCPY $ac_have_decl
 _ACEOF
-ac_fn_c_check_decl "$LINENO" "strnlen" "ac_cv_have_decl_strnlen" "$ac_includes_default"
-if test "x$ac_cv_have_decl_strnlen" = xyes; then :
-  ac_have_decl=1
-else
-  ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_STRNLEN $ac_have_decl
-_ACEOF
 ac_fn_c_check_decl "$LINENO" "strsep" "ac_cv_have_decl_strsep" "$ac_includes_default"
 if test "x$ac_cv_have_decl_strsep" = xyes; then :
   ac_have_decl=1
@@ -16268,19 +16258,6 @@ esac
 
 fi
 
-ac_fn_c_check_func "$LINENO" "strnlen" "ac_cv_func_strnlen"
-if test "x$ac_cv_func_strnlen" = xyes; then :
-  $as_echo "#define HAVE_STRNLEN 1" >>confdefs.h
-
-else
-  case " $LIBOBJS " in
-  *" strnlen.$ac_objext "* ) ;;
-  *) LIBOBJS="$LIBOBJS strnlen.$ac_objext"
- ;;
-esac
-
-fi
-
 ac_fn_c_check_func "$LINENO" "strsep" "ac_cv_func_strsep"
 if test "x$ac_cv_func_strsep" = xyes; then :
   $as_echo "#define HAVE_STRSEP 1" >>confdefs.h
index b90a220a6358cef77a5e1b472b7cf5891c2efc70..145197e6bd63f444b09aba5fd5f67d464b379269 100644 (file)
@@ -1823,7 +1823,7 @@ AC_CHECK_DECLS(posix_fadvise, [], [], [#include <fcntl.h>])
 ]) # fi
 
 AC_CHECK_DECLS(fdatasync, [], [], [#include <unistd.h>])
-AC_CHECK_DECLS([strlcat, strlcpy, strnlen, strsep, timingsafe_bcmp])
+AC_CHECK_DECLS([strlcat, strlcpy, strsep, timingsafe_bcmp])
 
 # We can't use AC_CHECK_FUNCS to detect these functions, because it
 # won't handle deployment target restrictions on macOS
@@ -1844,7 +1844,6 @@ AC_REPLACE_FUNCS(m4_normalize([
    mkdtemp
    strlcat
    strlcpy
-   strnlen
    strsep
    timingsafe_bcmp
 ]))
index 35eb47468db6b09943032bf3cb0501d63bf613fc..2064d1b0a8d653dd6f632d9d4d4ddc200b26dd02 100644 (file)
@@ -2666,7 +2666,6 @@ decl_checks = [
   ['posix_fadvise', 'fcntl.h'],
   ['strlcat', 'string.h'],
   ['strlcpy', 'string.h'],
-  ['strnlen', 'string.h'],
   ['strsep',  'string.h'],
   ['timingsafe_bcmp',  'string.h'],
 ]
@@ -2914,7 +2913,6 @@ func_checks = [
   ['strerror_r', {'dependencies': [thread_dep]}],
   ['strlcat'],
   ['strlcpy'],
-  ['strnlen'],
   ['strsep'],
   ['strsignal'],
   ['sync_file_range'],
index 2dd8f6b9a385fa889e65b668b502b5d5dec50f76..10fa85e78c262b0c15978c15c64fca108d4c4d94 100644 (file)
    don't. */
 #undef HAVE_DECL_STRLCPY
 
-/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
-   don't. */
-#undef HAVE_DECL_STRNLEN
-
 /* Define to 1 if you have the declaration of `strsep', and to 0 if you don't.
    */
 #undef HAVE_DECL_STRSEP
 /* Define to 1 if you have the `strlcpy' function. */
 #undef HAVE_STRLCPY
 
-/* Define to 1 if you have the `strnlen' function. */
-#undef HAVE_STRNLEN
-
 /* Define to 1 if you have the `strsep' function. */
 #undef HAVE_STRSEP
 
index ae43620c7e7d81801f8c1f5af0f39e5f135e5625..51df9b80e7d56e10cb9eaf4431bfa9cd793b85ca 100644 (file)
@@ -476,10 +476,6 @@ extern size_t strlcat(char *dst, const char *src, size_t siz);
 extern size_t strlcpy(char *dst, const char *src, size_t siz);
 #endif
 
-#if !HAVE_DECL_STRNLEN
-extern size_t strnlen(const char *str, size_t maxlen);
-#endif
-
 #if !HAVE_DECL_STRSEP
 extern char *strsep(char **stringp, const char *delim);
 #endif
index c1ef6fd4821f98bb4969680fcd85392e77e38887..28655142ebe27e5009d842ebfd8b8348967b1ae4 100644 (file)
@@ -72,7 +72,6 @@ replace_funcs_neg = [
   ['mkdtemp'],
   ['strlcat'],
   ['strlcpy'],
-  ['strnlen'],
   ['strsep'],
   ['timingsafe_bcmp'],
 ]
diff --git a/src/port/strnlen.c b/src/port/strnlen.c
deleted file mode 100644 (file)
index 13f8737..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * strnlen.c
- *     Fallback implementation of strnlen().
- *
- *
- * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * IDENTIFICATION
- *   src/port/strnlen.c
- *
- *-------------------------------------------------------------------------
- */
-
-#include "c.h"
-
-/*
- * Implementation of posix' strnlen for systems where it's not available.
- *
- * Returns the number of characters before a null-byte in the string pointed
- * to by str, unless there's no null-byte before maxlen. In the latter case
- * maxlen is returned.
- */
-size_t
-strnlen(const char *str, size_t maxlen)
-{
-   const char *p = str;
-
-   while (maxlen-- > 0 && *p)
-       p++;
-   return p - str;
-}