]> Savannah Git Hosting - gnulib.git/commitdiff
strncpy tests: Verify N3322 functionality.
authorBruno Haible <bruno@clisp.org>
Tue, 5 Nov 2024 20:10:13 +0000 (21:10 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 5 Nov 2024 21:19:16 +0000 (22:19 +0100)
* modules/strncpy: New file.
* doc/posix-functions/strncpy.texi: Mention the new module.
* tests/test-strncpy.c: New file.
* modules/strncpy-tests: New file.

ChangeLog
doc/posix-functions/strncpy.texi
modules/strncpy [new file with mode: 0644]
modules/strncpy-tests [new file with mode: 0644]
tests/test-strncpy.c [new file with mode: 0644]

index a8fde5dfbc14cc5755b6e3e8cf9cfc3d5b3c7e2a..d0514e69b050064060c7814dbd177cf82ad66424 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-11-05  Bruno Haible  <bruno@clisp.org>
+
+       strncpy tests: Verify N3322 functionality.
+       * modules/strncpy: New file.
+       * doc/posix-functions/strncpy.texi: Mention the new module.
+       * tests/test-strncpy.c: New file.
+       * modules/strncpy-tests: New file.
+
 2024-11-05  Bruno Haible  <bruno@clisp.org>
 
        memmove tests: Verify N3322 functionality.
index 343ff249a98496707796a00390ff7dca801e448a..ea5f41dcceb38a2a21cf8e8cd33875df255614ec 100644 (file)
@@ -4,10 +4,11 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncpy.html}
 
-Gnulib module: string
+Gnulib module: string or strncpy
 @mindex string
+@mindex strncpy
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by Gnulib module @code{string} or Gnulib module @code{strncpy}:
 @itemize
 @item
 This function cannot be called from plain inline or extern inline functions
diff --git a/modules/strncpy b/modules/strncpy
new file mode 100644 (file)
index 0000000..de91ffd
--- /dev/null
@@ -0,0 +1,26 @@
+Description:
+Copy the initial part of a string.
+
+Status:
+obsolete
+
+Notice:
+This module is obsolete.
+
+Files:
+
+Depends-on:
+string
+
+configure.ac:
+
+Makefile.am:
+
+Include:
+<string.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/strncpy-tests b/modules/strncpy-tests
new file mode 100644 (file)
index 0000000..c21d2ac
--- /dev/null
@@ -0,0 +1,11 @@
+Files:
+tests/test-strncpy.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-strncpy
+check_PROGRAMS += test-strncpy
diff --git a/tests/test-strncpy.c b/tests/test-strncpy.c
new file mode 100644 (file)
index 0000000..518b43d
--- /dev/null
@@ -0,0 +1,44 @@
+/* Test of strncpy() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <string.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (strncpy (NULL, "x", 0) == NULL);
+  ASSERT (value);
+
+  {
+    char y[1];
+    value = (strncpy (y, NULL, 0) == y);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}