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

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

index c3e15d31d4467eaf674902bf724cfa3a86e3afb9..55cbc80e0fe0d1af04b58f8f62cc60d8bca22d30 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-11-05  Bruno Haible  <bruno@clisp.org>
+
+       bsearch tests: Verify N3322 functionality.
+       * modules/bsearch: New file.
+       * doc/posix-functions/bsearch.texi: Mention the new module.
+       * tests/test-bsearch.c: New file.
+       * modules/bsearch-tests: New file.
+
 2024-11-05  Bruno Haible  <bruno@clisp.org>
 
        realloc-posix: Avoid use of AC_LIBOBJ.
index 1ec4e9351b81c2ae4e4f66c388122d9f06b5dd7b..96c41f6db6cbb1384f84aff9e4c9e9a535a5fb6a 100644 (file)
@@ -4,7 +4,8 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/bsearch.html}
 
-Gnulib module: ---
+Gnulib module: bsearch
+@mindex bsearch
 
 Portability problems fixed by Gnulib:
 @itemize
diff --git a/modules/bsearch b/modules/bsearch
new file mode 100644 (file)
index 0000000..5962172
--- /dev/null
@@ -0,0 +1,25 @@
+Description:
+Binary search in a sorted array.
+
+Status:
+obsolete
+
+Notice:
+This module is obsolete.
+
+Files:
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+
+Include:
+<stdlib.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/bsearch-tests b/modules/bsearch-tests
new file mode 100644 (file)
index 0000000..81a1c15
--- /dev/null
@@ -0,0 +1,11 @@
+Files:
+tests/test-bsearch.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-bsearch
+check_PROGRAMS += test-bsearch
diff --git a/tests/test-bsearch.c b/tests/test-bsearch.c
new file mode 100644 (file)
index 0000000..8d62dc3
--- /dev/null
@@ -0,0 +1,42 @@
+/* Test of bsearch() 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 <stdlib.h>
+
+#include "macros.h"
+
+static int
+cmp (const void *a, const void *b)
+{
+  return 0;
+}
+
+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 = (bsearch ("x", NULL, 0, 1, cmp) == NULL);
+  ASSERT (value);
+
+  return test_exit_status;
+}