]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Limit the set of strings.h functions also exposed in string.h.
authorZack Weinberg <zackw@panix.com>
Sun, 17 Mar 2019 01:01:12 +0000 (21:01 -0400)
committerZack Weinberg <zackw@panix.com>
Wed, 8 Jan 2020 18:42:38 +0000 (13:42 -0500)
As someone who can remember when you might not be able to include both
string.h and strings.h at the same time, it annoys me that strings.h
still exists and is the only standard source for str(n)casecmp(_l) and
ffs.  I think it’s right that we expose those functions from string.h.
However, there’s no reason we need to keep exposing the other obsolete
functions that strings.h declares from string.h.

This patch creates <bits/strings_x2k8.h>, which declares the
non-obsolete functions whose official home is strings.h.  strings.h
includes it unconditionally, and string.h includes it under
__USE_MISC, instead of strings.h.

Two tests of the obsolete strings.h functions had to be adjusted.

* string/strings.h (strcasecmp, strncasecmp, strcasecmp_l)
(strncasecmp_l, ffs, ffsl, ffsll): Move declarations to...
* string/bits/strings_x2k8.h: ... this new file.
* string/Makefile: Install bits/strings_x2k8.h.
* include/bits/strings_x2k8h: New wrapper.
* string/string.h: Include bits/strings_x2k8.h instead of
strings.h.

* debug/tst-chk1.c, string/test-string.h: Include strings.h.
* scripts/check-obsolete-constructs.py: string.h is no longer
expected to include strings.h.

* sysdeps/i386/i686/multiarch/bcopy.c
* sysdeps/i386/i686/multiarch/bzero.c
* sysdeps/i386/i686/multiarch/ifunc-impl-list.c
* sysdeps/powerpc/powerpc32/power4/multiarch/ifunc-impl-list.c
* sysdeps/powerpc/powerpc64/multiarch/bcopy-ppc64.c
* sysdeps/powerpc/powerpc64/multiarch/bcopy.c
* sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
* sysdeps/s390/bzero.c
* sysdeps/s390/multiarch/ifunc-impl-list.c
* sysdeps/sparc/sparc64/multiarch/bzero.c
* sysdeps/sparc/sparc64/multiarch/ifunc-impl-list.c:
        Include strings.h.

20 files changed:
NEWS
debug/tst-chk1.c
include/bits/strings_x2k8.h [new file with mode: 0644]
scripts/check-obsolete-constructs.py
string/Makefile
string/bits/strings_x2k8.h [new file with mode: 0644]
string/string.h
string/strings.h
string/test-string.h
sysdeps/i386/i686/multiarch/bcopy.c
sysdeps/i386/i686/multiarch/bzero.c
sysdeps/i386/i686/multiarch/ifunc-impl-list.c
sysdeps/powerpc/powerpc32/power4/multiarch/ifunc-impl-list.c
sysdeps/powerpc/powerpc64/multiarch/bcopy-ppc64.c
sysdeps/powerpc/powerpc64/multiarch/bcopy.c
sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
sysdeps/s390/bzero.c
sysdeps/s390/multiarch/ifunc-impl-list.c
sysdeps/sparc/sparc64/multiarch/bzero.c
sysdeps/sparc/sparc64/multiarch/ifunc-impl-list.c

diff --git a/NEWS b/NEWS
index 599db8f4f9b93b33fabebf1276560f98d57e075a..93be478f33349efd4139dd338f0c8c58102b4ef6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -187,6 +187,9 @@ Deprecated and removed features, and other changes affecting compatibility:
 * The obsolete and never-implemented XSI STREAMS header files <stropts.h>
   and <sys/stropts.h> have been removed.
 
+* The obsolete functions bcmp, bcopy, bzero, index, and rindex are no
+  longer declared in <string.h>, only <strings.h>.
+
 * The typedefs u_int8_t, u_int16_t, u_int32_t, u_int64_t, and register_t
   are no longer defined by <sys/types.h> in strict conformance modes.
   These types were historically provided by <sys/types.h> on BSD systems,
index 5d02592978b96ad38efd6d40edb288f674c55030..ae7d0c289af95b3e7f646a71f9d48c05d801ec2b 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <strings.h>
 #include <unistd.h>
 #include <wchar.h>
 #include <sys/poll.h>
diff --git a/include/bits/strings_x2k8.h b/include/bits/strings_x2k8.h
new file mode 100644 (file)
index 0000000..7eddd92
--- /dev/null
@@ -0,0 +1 @@
+#include <string/bits/strings_x2k8.h>
index 77253dfb1d4f11d5d1fee62542ff6ad30c679a35..dfe0d0fff5eab42e41ffd3405d9567b53a0d742f 100755 (executable)
@@ -506,7 +506,6 @@ HEADER_ALLOWED_INCLUDES = {
     "inttypes.h":                  [ "stdint.h" ],
     "signal.h":                    [ "sys/ucontext.h" ],
     "stdlib.h":                    [ "alloca.h", "sys/types.h" ],
-    "string.h":                    [ "strings.h" ],
     "tgmath.h":                    [ "complex.h", "math.h" ],
     "threads.h":                   [ "time.h" ],
 
index c46785f1a13ec12b13839bc9925564b9b2eb8c3f..d9503bd2b3520dbce0a0fd3a0199bacae6e6b041 100644 (file)
@@ -23,7 +23,7 @@ subdir        := string
 include ../Makeconfig
 
 headers                := string.h bits/string_fortified.h                     \
-                  strings.h bits/strings_fortified.h                   \
+                  strings.h bits/strings_x2k8.h bits/strings_fortified.h \
                   byteswap.h bits/byteswap.h                           \
                   endian.h bits/endian.h bits/endianness.h             \
                   bits/uintn-identity.h                                \
diff --git a/string/bits/strings_x2k8.h b/string/bits/strings_x2k8.h
new file mode 100644 (file)
index 0000000..dbcb0b2
--- /dev/null
@@ -0,0 +1,70 @@
+/* Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _BITS_STRINGS_X2K8_H
+#define _BITS_STRINGS_X2K8_H 1
+
+/* This header file declares all of the strings.h functions that are
+   not marked as "obsolete" in POSIX.1-2008.  As a GNU extension,
+   these functions are also made available via string.h.  */
+
+#if !defined _STRING_H && !defined _STRINGS_H
+# error "Never include <bits/strings_x2k8.h> directly, use <string(s).h>."
+#endif
+
+__BEGIN_DECLS
+
+/* Compare S1 and S2, ignoring case.  */
+extern int strcasecmp (const char *__s1, const char *__s2)
+     __THROW __attribute_pure__ __nonnull ((1, 2));
+
+/* Compare no more than N chars of S1 and S2, ignoring case.  */
+extern int strncasecmp (const char *__s1, const char *__s2, size_t __n)
+     __THROW __attribute_pure__ __nonnull ((1, 2));
+
+#ifdef __USE_XOPEN2K8
+/* POSIX.1-2008 extended locale interface (see locale.h).  */
+# include <bits/types/locale_t.h>
+
+/* Compare S1 and S2, ignoring case, using collation rules from LOC.  */
+extern int strcasecmp_l (const char *__s1, const char *__s2, locale_t __loc)
+     __THROW __attribute_pure__ __nonnull ((1, 2, 3));
+
+/* Compare no more than N chars of S1 and S2, ignoring case, using
+   collation rules from LOC.  */
+extern int strncasecmp_l (const char *__s1, const char *__s2,
+                         size_t __n, locale_t __loc)
+     __THROW __attribute_pure__ __nonnull ((1, 2, 4));
+#endif
+
+#if defined __USE_MISC || !defined __USE_XOPEN2K8 || defined __USE_XOPEN2K8XSI
+/* Return the position of the first bit set in I, or 0 if none are set.
+   The least-significant bit is position 1, the most-significant 32.  */
+extern int ffs (int __i) __THROW __attribute_const__;
+#endif
+
+/* The following two functions are non-standard but necessary for non-32 bit
+   platforms.  */
+#ifdef __USE_MISC
+extern int ffsl (long int __l) __THROW __attribute_const__;
+__extension__ extern int ffsll (long long int __ll)
+     __THROW __attribute_const__;
+#endif
+
+__END_DECLS
+
+#endif /* bits/strings_x2k8.h */
index 234ee91d4a326cc81cd674bb2324a9fba5a61e16..fcb7da84ec9cbb15bd76decff0b708ff959f4ce8 100644 (file)
@@ -427,7 +427,7 @@ extern char *strerror_l (int __errnum, locale_t __l) __THROW;
 #endif
 
 #ifdef __USE_MISC
-# include <strings.h>
+# include <bits/strings_x2k8.h>
 
 /* Set N bytes of S to 0.  The compiler will not delete a call to this
    function, even if S is dead after the call.  */
index 65dfca89357b92531378bd7e72d6904e86b4f247..540eb1514fa7dc73ae42da5df99de4335cd27144 100644 (file)
@@ -21,6 +21,8 @@
 #include <features.h>
 #include <bits/types/size_t.h>
 
+#include <bits/strings_x2k8.h>
+
 /* Tell the caller that we provide correct C++ prototypes.  */
 #if defined __cplusplus && __GNUC_PREREQ (4, 4)
 # define __CORRECT_ISO_CPP_STRINGS_H_PROTO
@@ -97,43 +99,6 @@ extern char *rindex (const char *__s, int __c)
 # endif
 #endif
 
-#if defined __USE_MISC || !defined __USE_XOPEN2K8 || defined __USE_XOPEN2K8XSI
-/* Return the position of the first bit set in I, or 0 if none are set.
-   The least-significant bit is position 1, the most-significant 32.  */
-extern int ffs (int __i) __THROW __attribute_const__;
-#endif
-
-/* The following two functions are non-standard but necessary for non-32 bit
-   platforms.  */
-# ifdef        __USE_MISC
-extern int ffsl (long int __l) __THROW __attribute_const__;
-__extension__ extern int ffsll (long long int __ll)
-     __THROW __attribute_const__;
-# endif
-
-/* Compare S1 and S2, ignoring case.  */
-extern int strcasecmp (const char *__s1, const char *__s2)
-     __THROW __attribute_pure__ __nonnull ((1, 2));
-
-/* Compare no more than N chars of S1 and S2, ignoring case.  */
-extern int strncasecmp (const char *__s1, const char *__s2, size_t __n)
-     __THROW __attribute_pure__ __nonnull ((1, 2));
-
-#ifdef __USE_XOPEN2K8
-/* POSIX.1-2008 extended locale interface (see locale.h).  */
-# include <bits/types/locale_t.h>
-
-/* Compare S1 and S2, ignoring case, using collation rules from LOC.  */
-extern int strcasecmp_l (const char *__s1, const char *__s2, locale_t __loc)
-     __THROW __attribute_pure__ __nonnull ((1, 2, 3));
-
-/* Compare no more than N chars of S1 and S2, ignoring case, using
-   collation rules from LOC.  */
-extern int strncasecmp_l (const char *__s1, const char *__s2,
-                         size_t __n, locale_t __loc)
-     __THROW __attribute_pure__ __nonnull ((1, 2, 4));
-#endif
-
 __END_DECLS
 
 #if __GNUC_PREREQ (3,4) && __USE_FORTIFY_LEVEL > 0 \
index 0efe5d870ead0c610cb1d97cbdc2c92063d48630..a6d8d1eb80f4eddeb525fe2afc1530104f2f0c7a 100644 (file)
@@ -55,6 +55,7 @@ extern impl_t __start_impls[], __stop_impls[];
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <strings.h>
 #include <sys/mman.h>
 #include <sys/param.h>
 #include <unistd.h>
index 2145ab7e69fb489ea369eaf57f4d36c105fbce03..929dc70321ada7f8b94428fc16f49309349addbe 100644 (file)
@@ -21,6 +21,7 @@
 #if IS_IN (libc)
 # define bcopy __redirect_bcopy
 # include <string.h>
+# include <strings.h>
 # undef bcopy
 
 # define SYMBOL_NAME bcopy
index 3b68e1c1134c500b66a91e8319dff5ea23d0834e..3655262f1b16b4b21048171f731e758ee2200358 100644 (file)
@@ -21,6 +21,7 @@
 #if IS_IN (libc)
 # define bzero __redirect_bzero
 # include <string.h>
+# include <strings.h>
 # undef bzero
 
 # define SYMBOL_NAME bzero
index 23774fbe8a7fe872c5f37469677c21c9308cc6ec..8101c0a2db2c462d97a92aec09e1306190adff51 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <strings.h>
 #include <wchar.h>
 #include <ifunc-impl-list.h>
 #include "init-arch.h"
index fca6c2cbef72c1b70f4ba04e89be402eb4814d3f..07de0a96abe210d812eced1daa9a4533cf27585d 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <strings.h>
 #include <wchar.h>
 #include <ldsodefs.h>
 #include <ifunc-impl-list.h>
index 0851afa313806ededdb19531e09d748602bcfaf9..4b530cdb6d91d46e0b86a1482e229f7b48b62726 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <string.h>
+#include <strings.h>
 
 extern __typeof (bcopy)   __bcopy_ppc attribute_hidden;
 extern __typeof (memmove) __memmove_ppc attribute_hidden;
index 2aebfc0a8e1cdf1430b0dde392cccc800c6932a9..1a7c9099d9c4c4d7e1890ef23b615ee2c261c82b 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <string.h>
+#include <strings.h>
 #include "init-arch.h"
 
 extern __typeof (bcopy) __bcopy_ppc attribute_hidden;
index b9fef3f43c91b2fa3e6efb4eecfbdd5131bbbb30..41d133051d70bccb09f3fb2926129e953ffe9921 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <strings.h>
 #include <wchar.h>
 #include <ldsodefs.h>
 #include <ifunc-impl-list.h>
index fc0d46e2e1bcfaa216dac732fa08ca9422d1c8cc..fc641e12fc905cb12f74bb00585ab6eeb98ba3c7 100644 (file)
@@ -19,6 +19,7 @@
 #include <ifunc-memset.h>
 #if HAVE_MEMSET_IFUNC
 # include <string.h>
+# include <strings.h>
 # include <ifunc-resolve.h>
 
 # if HAVE_MEMSET_Z900_G5
index e6195c6e261efcbd0a253aa451a69a830cdec8df..0d94949145e63a543436dcad6fff9ba5b9b9d8d8 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <strings.h>
 #include <wchar.h>
 #include <ifunc-impl-list.h>
 #include <ifunc-resolve.h>
index ee501502aadc68a92d534e26724d82ef413742da..fc7af26d840927cbf40184f4ddf89ed8d0d3dd79 100644 (file)
@@ -20,6 +20,7 @@
 #if IS_IN (libc)
 # define bzero __redirect_bzero
 # include <string.h>
+# include <strings.h>
 # undef bzero
 
 # include <sparc-ifunc.h>
index ad79a26169ab5bd59d7c625fe71591505afd2973..2fa7a3a9ef2f599b08b2f3e80fade5165b312299 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <strings.h>
 #include <wchar.h>
 #include <ldsodefs.h>
 #include <sysdep.h>