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

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

index 79c9c8ed36e67fdffd520008d5c36921bc4ed654..699893401b4110564eea5a811ffeb9708a0bbb91 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-11-05  Bruno Haible  <bruno@clisp.org>
+
+       strncmp tests: Verify N3322 functionality.
+       * modules/strncmp: New file.
+       * doc/posix-functions/strncmp.texi: Mention the new module.
+       * tests/test-strncmp.c: New file.
+       * modules/strncmp-tests: New file.
+
 2024-11-05  Bruno Haible  <bruno@clisp.org>
 
        memcmp tests: Verify N3322 functionality.
index df0f0afbeb722e27240da4204b5b9e57c3617962..2cccd766ea71deb3b19a981a17144f7ae99bcf5f 100644 (file)
@@ -4,7 +4,8 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncmp.html}
 
-Gnulib module: ---
+Gnulib module: strncmp
+@mindex strncmp
 
 Portability problems fixed by Gnulib:
 @itemize
diff --git a/modules/strncmp b/modules/strncmp
new file mode 100644 (file)
index 0000000..443c367
--- /dev/null
@@ -0,0 +1,25 @@
+Description:
+Compare the initial part of two strings.
+
+Status:
+obsolete
+
+Notice:
+This module is obsolete.
+
+Files:
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+
+Include:
+<string.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/strncmp-tests b/modules/strncmp-tests
new file mode 100644 (file)
index 0000000..a3a34c0
--- /dev/null
@@ -0,0 +1,11 @@
+Files:
+tests/test-strncmp.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-strncmp
+check_PROGRAMS += test-strncmp
diff --git a/tests/test-strncmp.c b/tests/test-strncmp.c
new file mode 100644 (file)
index 0000000..51c2be4
--- /dev/null
@@ -0,0 +1,44 @@
+/* Test of strncmp() 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 = (strncmp (NULL, "x", 0) == 0);
+  ASSERT (value);
+
+  value = (strncmp ("x", NULL, 0) == 0);
+  ASSERT (value);
+
+  value = (strncmp (NULL, NULL, 0) == 0);
+  ASSERT (value);
+
+  return test_exit_status;
+}