]> Savannah Git Hosting - gnulib.git/commitdiff
strndup: Guarantee N3322 functionality.
authorBruno Haible <bruno@clisp.org>
Tue, 5 Nov 2024 20:10:20 +0000 (21:10 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 5 Nov 2024 21:19:17 +0000 (22:19 +0100)
* m4/strndup.m4 (gl_FUNC_STRNDUP): Check against the AIX bug.
* doc/posix-functions/strndup.texi: Mention the AIX bug.

ChangeLog
doc/posix-functions/strndup.texi
m4/strndup.m4

index d0514e69b050064060c7814dbd177cf82ad66424..06ccb74f9abdff3c5eae60b2b5f34943c841eada 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-11-05  Bruno Haible  <bruno@clisp.org>
+
+       strndup: Guarantee N3322 functionality.
+       * m4/strndup.m4 (gl_FUNC_STRNDUP): Check against the AIX bug.
+       * doc/posix-functions/strndup.texi: Mention the AIX bug.
+
 2024-11-05  Bruno Haible  <bruno@clisp.org>
 
        strncpy tests: Verify N3322 functionality.
index 556e0602f16ac890cb5d7c921e6cfe1cbad68fd5..4baabe2f5b0b74d66e4b43a135c7f4cb66a8e7b1 100644 (file)
@@ -15,6 +15,10 @@ Mac OS X 10.5, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, Sola
 @item
 This function does not NUL-terminate the result on some platforms:
 AIX 5.1.
+@item
+This function does not support zero-length operations on NULL pointers
+on some platforms:
+AIX 7.3.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 7e5aa08698f407c7580c2faefa47f91579485936..9c8b212fddca8134730eb5a31782acce5a5aabc1 100644 (file)
@@ -1,5 +1,5 @@
 # strndup.m4
-# serial 23
+# serial 24
 dnl Copyright (C) 2002-2003, 2005-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -21,7 +21,8 @@ AC_DEFUN([gl_FUNC_STRNDUP],
 
   if test $ac_cv_func_strndup = yes; then
     HAVE_STRNDUP=1
-    # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
+    dnl AIX 5.1 has a function that fails to add the terminating '\0'.
+    dnl AIX 7.3 has a function that does not support a zero length.
     AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup_works],
       [AC_RUN_IFELSE([
          AC_LANG_PROGRAM([[#include <string.h>
@@ -33,23 +34,24 @@ AC_DEFUN([gl_FUNC_STRNDUP],
   #endif
   char *strndup (const char *, size_t);
 #endif
-  int result;
-  char *s;
-  s = strndup ("some longer string", 15);
-  free (s);
-  s = strndup ("shorter string", 13);
-  result = s[13] != '\0';
-  free (s);
+  int result = 0;
+  {
+    char *s = strndup ("some longer string", 15);
+    free (s);
+    s = strndup ("shorter string", 13);
+    if (s[13] != '\0')
+      result |= 1;
+    free (s);
+  }
+  if (strndup (NULL, 0) == NULL)
+    result |= 2;
   return result;]])],
          [gl_cv_func_strndup_works=yes],
          [gl_cv_func_strndup_works=no],
-         [
-changequote(,)dnl
-          case $host_os in
-            aix | aix[3-6]*) gl_cv_func_strndup_works="guessing no";;
-            *)               gl_cv_func_strndup_works="guessing yes";;
+         [case $host_os in
+            aix*) gl_cv_func_strndup_works="guessing no";;
+            *)    gl_cv_func_strndup_works="guessing yes";;
           esac
-changequote([,])dnl
          ])])
     case $gl_cv_func_strndup_works in
       *no) REPLACE_STRNDUP=1 ;;