From b77d357ea356134fbc159797b34498b7a0006dc9 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 14 May 2023 18:51:22 -0700 Subject: Update from Gnulib by running admin/merge-gnulib * lib/dirent-private.h, m4/codeset.m4, m4/locale-fr.m4, m4/musl.m4: New files, from Gnulib. --- lib/acl-internal.h | 8 +-- lib/acl.h | 5 ++ lib/attribute.h | 15 ++++++ lib/binary-io.h | 8 +-- lib/c++defs.h | 6 +++ lib/c-ctype.h | 4 +- lib/c-strcase.h | 5 ++ lib/careadlinkat.h | 5 ++ lib/count-leading-zeros.h | 8 +-- lib/count-one-bits.h | 8 +-- lib/count-trailing-zeros.h | 8 +-- lib/dirent-private.h | 67 ++++++++++++++++++++++++ lib/dirent.in.h | 49 +++++++++++++++--- lib/dirfd.c | 17 ++++-- lib/eloop-threshold.h | 5 ++ lib/execinfo.in.h | 4 +- lib/fcntl.in.h | 5 ++ lib/fdopendir.c | 97 ++++++++++++++++++++++------------- lib/file-has-acl.c | 96 ++++++++++++++++++++++++---------- lib/filemode.h | 6 +++ lib/filevercmp.h | 5 ++ lib/flexmember.h | 5 ++ lib/fpending.h | 6 +++ lib/gnulib.mk.in | 19 +++++++ lib/inttypes.in.h | 5 ++ lib/limits.in.h | 5 ++ lib/malloc/dynarray_emplace_enlarge.c | 4 +- lib/malloc/dynarray_resize.c | 4 +- lib/md5.h | 5 ++ lib/minmax.h | 5 ++ lib/mktime.c | 11 ++-- lib/openat.h | 9 ++-- lib/pathmax.h | 5 ++ lib/pselect.c | 6 +++ lib/regex_internal.h | 3 +- lib/regexec.c | 2 +- lib/sha1.h | 5 ++ lib/sha256.h | 5 ++ lib/sha512.h | 5 ++ lib/signal.in.h | 5 ++ lib/stat-time.h | 9 ++-- lib/stddef.in.h | 52 +++++++++++++++++-- lib/stdio.in.h | 84 ++++++++++++++++++++++++++---- lib/stdlib.in.h | 63 +++++++++++++++++++++-- lib/string.in.h | 6 +++ lib/strtol.c | 14 +++-- lib/sys_random.in.h | 5 ++ lib/sys_select.in.h | 12 +++++ lib/sys_stat.in.h | 12 +++++ lib/sys_time.in.h | 12 +++++ lib/sys_types.in.h | 7 +++ lib/time.in.h | 17 ++++++ lib/timespec.h | 9 ++-- lib/u64.h | 8 +-- lib/unistd.in.h | 9 ++-- lib/unlocked-io.h | 5 ++ lib/utimens.h | 8 +-- lib/verify.h | 34 +++++++----- 58 files changed, 758 insertions(+), 153 deletions(-) create mode 100644 lib/dirent-private.h (limited to 'lib') diff --git a/lib/acl-internal.h b/lib/acl-internal.h index c97e847cdc5..496e41d7b21 100644 --- a/lib/acl-internal.h +++ b/lib/acl-internal.h @@ -17,6 +17,11 @@ Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible. */ +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_ATTRIBUTE_PURE. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include "acl.h" #include @@ -60,9 +65,6 @@ extern int aclsort (int, int, struct acl *); # define fchmod(fd, mode) (-1) #endif -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif _GL_INLINE_HEADER_BEGIN #ifndef ACL_INTERNAL_INLINE # define ACL_INTERNAL_INLINE _GL_INLINE diff --git a/lib/acl.h b/lib/acl.h index 58e5797179e..0d021200556 100644 --- a/lib/acl.h +++ b/lib/acl.h @@ -20,6 +20,11 @@ #ifndef _GL_ACL_H #define _GL_ACL_H 1 +/* This file uses _GL_ATTRIBUTE_CONST. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include #include diff --git a/lib/attribute.h b/lib/attribute.h index 130644d8798..9464fde0f30 100644 --- a/lib/attribute.h +++ b/lib/attribute.h @@ -41,6 +41,21 @@ These names begin with 'ATTRIBUTE_' to avoid name clashes. */ +/* This file uses _GL_ATTRIBUTE_ALLOC_SIZE, _GL_ATTRIBUTE_ALWAYS_INLINE, + _GL_ATTRIBUTE_ARTIFICIAL, _GL_ATTRIBUTE_COLD, _GL_ATTRIBUTE_CONST, + _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_DEPRECATED, _GL_ATTRIBUTE_ERROR, + _GL_ATTRIBUTE_WARNING, _GL_ATTRIBUTE_EXTERNALLY_VISIBLE, + _GL_ATTRIBUTE_FALLTHROUGH, _GL_ATTRIBUTE_FORMAT, _GL_ATTRIBUTE_LEAF, + _GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_MAY_ALIAS, _GL_ATTRIBUTE_MAYBE_UNUSED, + _GL_ATTRIBUTE_NODISCARD, _GL_ATTRIBUTE_NOINLINE, _GL_ATTRIBUTE_NONNULL, + _GL_ATTRIBUTE_NONSTRING, _GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PACKED, + _GL_ATTRIBUTE_PURE, _GL_ATTRIBUTE_RETURNS_NONNULL, + _GL_ATTRIBUTE_SENTINEL. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + + /* =============== Attributes for specific kinds of functions =============== */ /* Attributes for functions that should not be used. */ diff --git a/lib/binary-io.h b/lib/binary-io.h index 6f4db253354..855d6f819f0 100644 --- a/lib/binary-io.h +++ b/lib/binary-io.h @@ -17,6 +17,11 @@ #ifndef _BINARY_H #define _BINARY_H +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_UNUSED. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* For systems that distinguish between text and binary I/O. O_BINARY is guaranteed by the gnulib . */ #include @@ -25,9 +30,6 @@ so we include it here first. */ #include -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif _GL_INLINE_HEADER_BEGIN #ifndef BINARY_IO_INLINE # define BINARY_IO_INLINE _GL_INLINE diff --git a/lib/c++defs.h b/lib/c++defs.h index 8ad46951ad4..458c014de5c 100644 --- a/lib/c++defs.h +++ b/lib/c++defs.h @@ -99,6 +99,12 @@ Example: _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...) _GL_ARG_NONNULL ((1))); + + Note: Attributes, such as _GL_ATTRIBUTE_DEPRECATED, are supported in front + of a _GL_FUNCDECL_RPL invocation only in C mode, not in C++ mode. (That's + because + [[...]] extern "C" ; + is invalid syntax in C++.) */ #define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \ _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes) diff --git a/lib/c-ctype.h b/lib/c-ctype.h index 35ca83d7d43..cb0f4f3ba1f 100644 --- a/lib/c-ctype.h +++ b/lib/c-ctype.h @@ -23,9 +23,11 @@ #ifndef C_CTYPE_H #define C_CTYPE_H -#ifndef _GL_INLINE_HEADER_BEGIN +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */ +#if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." #endif + _GL_INLINE_HEADER_BEGIN #ifndef C_CTYPE_INLINE # define C_CTYPE_INLINE _GL_INLINE diff --git a/lib/c-strcase.h b/lib/c-strcase.h index 9bcca01b27c..5dfa96c41f4 100644 --- a/lib/c-strcase.h +++ b/lib/c-strcase.h @@ -18,6 +18,11 @@ #ifndef C_STRCASE_H #define C_STRCASE_H +/* This file uses _GL_ATTRIBUTE_PURE. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include diff --git a/lib/careadlinkat.h b/lib/careadlinkat.h index 201d0415fff..562cf013b75 100644 --- a/lib/careadlinkat.h +++ b/lib/careadlinkat.h @@ -20,6 +20,11 @@ #ifndef _GL_CAREADLINKAT_H #define _GL_CAREADLINKAT_H +/* This file uses HAVE_READLINKAT. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include #include diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h index 99151d695bf..9fe2a03ee09 100644 --- a/lib/count-leading-zeros.h +++ b/lib/count-leading-zeros.h @@ -19,12 +19,14 @@ #ifndef COUNT_LEADING_ZEROS_H #define COUNT_LEADING_ZEROS_H 1 +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include #include -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif _GL_INLINE_HEADER_BEGIN #ifndef COUNT_LEADING_ZEROS_INLINE # define COUNT_LEADING_ZEROS_INLINE _GL_INLINE diff --git a/lib/count-one-bits.h b/lib/count-one-bits.h index 01a60b77b85..2821a1fb75e 100644 --- a/lib/count-one-bits.h +++ b/lib/count-one-bits.h @@ -19,12 +19,14 @@ #ifndef COUNT_ONE_BITS_H #define COUNT_ONE_BITS_H 1 +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include #include -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif _GL_INLINE_HEADER_BEGIN #ifndef COUNT_ONE_BITS_INLINE # define COUNT_ONE_BITS_INLINE _GL_INLINE diff --git a/lib/count-trailing-zeros.h b/lib/count-trailing-zeros.h index ef8e164126a..9b33df76f6d 100644 --- a/lib/count-trailing-zeros.h +++ b/lib/count-trailing-zeros.h @@ -19,12 +19,14 @@ #ifndef COUNT_TRAILING_ZEROS_H #define COUNT_TRAILING_ZEROS_H 1 +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include #include -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif _GL_INLINE_HEADER_BEGIN #ifndef COUNT_TRAILING_ZEROS_INLINE # define COUNT_TRAILING_ZEROS_INLINE _GL_INLINE diff --git a/lib/dirent-private.h b/lib/dirent-private.h new file mode 100644 index 00000000000..012b6837198 --- /dev/null +++ b/lib/dirent-private.h @@ -0,0 +1,67 @@ +/* Private details of the DIR type. + Copyright (C) 2011-2023 Free Software Foundation, Inc. + + This file 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. + + This file 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 this program. If not, see . */ + +#ifndef _DIRENT_PRIVATE_H +#define _DIRENT_PRIVATE_H 1 + +#if HAVE_DIRENT_H /* mingw */ + +# undef DIR + +struct gl_directory +{ + /* File descriptor to close during closedir(). + Needed for implementing fdopendir(). */ + int fd_to_close; + /* Pointer to the real DIR. */ + DIR *real_dirp; +}; + +/* Restore definition from dirent.h. */ +# define DIR struct gl_directory + +#else /* MSVC */ + +# define WIN32_LEAN_AND_MEAN +# include + +/* Don't assume that UNICODE is not defined. */ +# undef WIN32_FIND_DATA +# define WIN32_FIND_DATA WIN32_FIND_DATAA + +struct gl_directory +{ + /* File descriptor to close during closedir(). + Needed for implementing fdopendir(). */ + int fd_to_close; + /* Status, or error code to produce in next readdir() call. + -2 means the end of the directory is already reached, + -1 means the entry was already filled by FindFirstFile, + 0 means the entry needs to be filled using FindNextFile. + A positive value is an error code. */ + int status; + /* Handle, reading the directory, at current position. */ + HANDLE current; + /* Found directory entry. */ + WIN32_FIND_DATA entry; + /* Argument to pass to FindFirstFile. It consists of the absolutized + directory name, followed by a directory separator and the wildcards. */ + char dir_name_mask[1]; +}; + +#endif + +#endif /* _DIRENT_PRIVATE_H */ diff --git a/lib/dirent.in.h b/lib/dirent.in.h index 2aaabd054a8..d409a031ec8 100644 --- a/lib/dirent.in.h +++ b/lib/dirent.in.h @@ -29,6 +29,12 @@ #ifndef _@GUARD_PREFIX@_DIRENT_H #define _@GUARD_PREFIX@_DIRENT_H +/* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC, + _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* Get ino_t. Needed on some systems, including glibc 2.8. */ #include @@ -50,11 +56,24 @@ struct dirent # define DT_LNK 10 /* symbolic link */ # define DT_SOCK 12 /* socket */ # define DT_WHT 14 /* whiteout */ -typedef struct gl_directory DIR; # define GNULIB_defined_struct_dirent 1 # endif #endif +#if !@DIR_HAS_FD_MEMBER@ +# if !GNULIB_defined_DIR +/* struct gl_directory is a type with a field 'int fd_to_close'. + It is needed for implementing fdopendir(). */ +struct gl_directory; +# if @HAVE_DIRENT_H@ +# define DIR struct gl_directory +# else +typedef struct gl_directory DIR; +# endif +# define GNULIB_defined_DIR 1 +# endif +#endif + /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers that can be freed by passing them as the Ith argument to the function F. */ @@ -143,7 +162,7 @@ _GL_CXXALIAS_SYS (opendir, DIR *, (const char *dir_name)); # endif _GL_CXXALIASWARN (opendir); #else -# if @GNULIB_CLOSEDIR@ && __GNUC__ >= 11 && !defined opendir +# if @GNULIB_CLOSEDIR@ && !GNULIB_defined_DIR && __GNUC__ >= 11 && !defined opendir /* For -Wmismatched-dealloc: Associate opendir with closedir or rpl_closedir. */ _GL_FUNCDECL_SYS (opendir, DIR *, @@ -161,10 +180,19 @@ _GL_WARN_ON_USE (opendir, "opendir is not portable - " #endif #if @GNULIB_READDIR@ -# if !@HAVE_READDIR@ +# if @REPLACE_READDIR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef readdir +# define readdir rpl_readdir +# endif +_GL_FUNCDECL_RPL (readdir, struct dirent *, (DIR *dirp) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (readdir, struct dirent *, (DIR *dirp)); +# else +# if !@HAVE_READDIR@ _GL_FUNCDECL_SYS (readdir, struct dirent *, (DIR *dirp) _GL_ARG_NONNULL ((1))); -# endif +# endif _GL_CXXALIAS_SYS (readdir, struct dirent *, (DIR *dirp)); +# endif _GL_CXXALIASWARN (readdir); #elif defined GNULIB_POSIXCHECK # undef readdir @@ -175,10 +203,19 @@ _GL_WARN_ON_USE (readdir, "readdir is not portable - " #endif #if @GNULIB_REWINDDIR@ -# if !@HAVE_REWINDDIR@ +# if @REPLACE_REWINDDIR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef rewinddir +# define rewinddir rpl_rewinddir +# endif +_GL_FUNCDECL_RPL (rewinddir, void, (DIR *dirp) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (rewinddir, void, (DIR *dirp)); +# else +# if !@HAVE_REWINDDIR@ _GL_FUNCDECL_SYS (rewinddir, void, (DIR *dirp) _GL_ARG_NONNULL ((1))); -# endif +# endif _GL_CXXALIAS_SYS (rewinddir, void, (DIR *dirp)); +# endif _GL_CXXALIASWARN (rewinddir); #elif defined GNULIB_POSIXCHECK # undef rewinddir diff --git a/lib/dirfd.c b/lib/dirfd.c index b2b1d25cdbd..75b2163c353 100644 --- a/lib/dirfd.c +++ b/lib/dirfd.c @@ -22,6 +22,10 @@ #include #include +#if GNULIB_defined_DIR +# include "dirent-private.h" +#endif + #ifdef __KLIBC__ # include # include @@ -78,11 +82,17 @@ _gl_unregister_dirp_fd (int fd) int dirfd (DIR *dir_p) { +#if GNULIB_defined_DIR + int fd = dir_p->fd_to_close; + if (fd == -1) + errno = EINVAL; + return fd; +#else int fd = DIR_TO_FD (dir_p); if (fd == -1) -#ifndef __KLIBC__ +# ifndef __KLIBC__ errno = ENOTSUP; -#else +# else { struct dirp_fd_list *dirp_fd; @@ -92,7 +102,8 @@ dirfd (DIR *dir_p) errno = EINVAL; } -#endif +# endif return fd; +#endif } diff --git a/lib/eloop-threshold.h b/lib/eloop-threshold.h index 510f261795d..d9b154e4868 100644 --- a/lib/eloop-threshold.h +++ b/lib/eloop-threshold.h @@ -19,6 +19,11 @@ #ifndef _ELOOP_THRESHOLD_H #define _ELOOP_THRESHOLD_H 1 +/* This file uses _GL_ATTRIBUTE_CONST. */ +#if !_LIBC && !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include #ifdef _LIBC # include diff --git a/lib/execinfo.in.h b/lib/execinfo.in.h index ff9293b6327..56b04d1d862 100644 --- a/lib/execinfo.in.h +++ b/lib/execinfo.in.h @@ -20,9 +20,11 @@ #ifndef _GL_EXECINFO_H #define _GL_EXECINFO_H -#ifndef _GL_INLINE_HEADER_BEGIN +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */ +#if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." #endif + _GL_INLINE_HEADER_BEGIN #ifndef _GL_EXECINFO_INLINE # define _GL_EXECINFO_INLINE _GL_INLINE diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h index e034eaf9f5a..d0bb85f30b5 100644 --- a/lib/fcntl.in.h +++ b/lib/fcntl.in.h @@ -74,6 +74,11 @@ #ifndef _@GUARD_PREFIX@_FCNTL_H #define _@GUARD_PREFIX@_FCNTL_H +/* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #ifndef __GLIBC__ /* Avoid namespace pollution on glibc systems. */ # include #endif diff --git a/lib/fdopendir.c b/lib/fdopendir.c index aa841e3e819..0f43d6ff349 100644 --- a/lib/fdopendir.c +++ b/lib/fdopendir.c @@ -25,44 +25,27 @@ #if !HAVE_FDOPENDIR -# include "openat.h" -# include "openat-priv.h" -# include "save-cwd.h" +# if GNULIB_defined_DIR +/* We are in control of the file descriptor of a DIR. */ -# if GNULIB_DIRENT_SAFER -# include "dirent--.h" -# endif - -# ifndef REPLACE_FCHDIR -# define REPLACE_FCHDIR 0 -# endif - -static DIR *fdopendir_with_dup (int, int, struct saved_cwd const *); -static DIR *fd_clone_opendir (int, struct saved_cwd const *); - -/* Replacement for POSIX fdopendir. +# include "dirent-private.h" - First, try to simulate it via opendir ("/proc/self/fd/..."). Failing - that, simulate it by using fchdir metadata, or by doing - save_cwd/fchdir/opendir(".")/restore_cwd. - If either the save_cwd or the restore_cwd fails (relatively unlikely), - then give a diagnostic and exit nonzero. - - If successful, the resulting stream is based on FD in - implementations where streams are based on file descriptors and in - applications where no other thread or signal handler allocates or - frees file descriptors. In other cases, consult dirfd on the result - to find out whether FD is still being used. +# if !REPLACE_FCHDIR +# error "unexpected configuration: GNULIB_defined_DIR but fchdir not replaced" +# endif - Otherwise, this function works just like POSIX fdopendir. +DIR * +fdopendir (int fd) +{ + char const *name = _gl_directory_name (fd); + DIR *dirp = name ? opendir (name) : NULL; + if (dirp != NULL) + dirp->fd_to_close = fd; + return dirp; +} - W A R N I N G: +# elif defined __KLIBC__ - Unlike other fd-related functions, this one places constraints on FD. - If this function returns successfully, FD is under control of the - dirent.h system, and the caller should not close or modify the state of - FD other than by the dirent.h functions. */ -# ifdef __KLIBC__ # include DIR * @@ -96,7 +79,48 @@ fdopendir (int fd) return dirp; } + # else +/* We are not in control of the file descriptor of a DIR, and therefore have to + play tricks with file descriptors before and after a call to opendir(). */ + +# include "openat.h" +# include "openat-priv.h" +# include "save-cwd.h" + +# if GNULIB_DIRENT_SAFER +# include "dirent--.h" +# endif + +# ifndef REPLACE_FCHDIR +# define REPLACE_FCHDIR 0 +# endif + +static DIR *fdopendir_with_dup (int, int, struct saved_cwd const *); +static DIR *fd_clone_opendir (int, struct saved_cwd const *); + +/* Replacement for POSIX fdopendir. + + First, try to simulate it via opendir ("/proc/self/fd/..."). Failing + that, simulate it by using fchdir metadata, or by doing + save_cwd/fchdir/opendir(".")/restore_cwd. + If either the save_cwd or the restore_cwd fails (relatively unlikely), + then give a diagnostic and exit nonzero. + + If successful, the resulting stream is based on FD in + implementations where streams are based on file descriptors and in + applications where no other thread or signal handler allocates or + frees file descriptors. In other cases, consult dirfd on the result + to find out whether FD is still being used. + + Otherwise, this function works just like POSIX fdopendir. + + W A R N I N G: + + Unlike other fd-related functions, this one places constraints on FD. + If this function returns successfully, FD is under control of the + dirent.h system, and the caller should not close or modify the state of + FD other than by the dirent.h functions. */ DIR * fdopendir (int fd) { @@ -119,7 +143,6 @@ fdopendir (int fd) return dir; } -# endif /* Like fdopendir, except that if OLDER_DUPFD is not -1, it is known to be a dup of FD which is less than FD - 1 and which will be @@ -188,7 +211,7 @@ fd_clone_opendir (int fd, struct saved_cwd const *cwd) if (proc_file != buf) free (proc_file); } -# if REPLACE_FCHDIR +# if REPLACE_FCHDIR if (! dir && EXPECTED_ERRNO (saved_errno)) { char const *name = _gl_directory_name (fd); @@ -203,7 +226,7 @@ fd_clone_opendir (int fd, struct saved_cwd const *cwd) return dp; } -# endif +# endif errno = saved_errno; return dir; } @@ -223,6 +246,8 @@ fd_clone_opendir (int fd, struct saved_cwd const *cwd) } } +# endif + #else /* HAVE_FDOPENDIR */ # include diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c index b31a2ea2523..38bc806dc49 100644 --- a/lib/file-has-acl.c +++ b/lib/file-has-acl.c @@ -29,7 +29,7 @@ #include "acl-internal.h" -#if USE_ACL && GETXATTR_WITH_POSIX_ACLS +#if USE_ACL && HAVE_LINUX_XATTR_H && HAVE_LISTXATTR # include # include # include @@ -44,6 +44,20 @@ enum { ACE4_IDENTIFIER_GROUP = 0x00000040 }; +/* Return true if ATTR is in the set represented by the NUL-terminated + strings in LISTBUF, which is of size LISTSIZE. */ + +static bool +have_xattr (char const *attr, char const *listbuf, ssize_t listsize) +{ + char const *blim = listbuf + listsize; + for (char const *b = listbuf; b < blim; b += strlen (b) + 1) + for (char const *a = attr; *a == *b; a++, b++) + if (!*a) + return true; + return false; +} + /* Return 1 if given ACL in XDR format is non-trivial, 0 if it is trivial. -1 upon failure to determine it. Possibly change errno. Assume that the ACL is valid, except avoid undefined behavior even if invalid. @@ -137,37 +151,65 @@ file_has_acl (char const *name, struct stat const *sb) if (! S_ISLNK (sb->st_mode)) { -# if GETXATTR_WITH_POSIX_ACLS - - ssize_t ret; +# if HAVE_LINUX_XATTR_H && HAVE_LISTXATTR int initial_errno = errno; - ret = getxattr (name, XATTR_NAME_POSIX_ACL_ACCESS, NULL, 0); - if (ret < 0 && errno == ENODATA) - ret = 0; - else if (ret > 0) - return 1; - - if (ret == 0 && S_ISDIR (sb->st_mode)) + /* The max length of a trivial NFSv4 ACL is 6 words for owner, + 6 for group, 7 for everyone, all times 2 because there are + both allow and deny ACEs. There are 6 words for owner + because of type, flag, mask, wholen, "OWNER@"+pad and + similarly for group; everyone is another word to hold + "EVERYONE@". */ + typedef uint32_t trivial_NFSv4_xattr_buf[2 * (6 + 6 + 7)]; + + /* A buffer large enough to hold any trivial NFSv4 ACL, + and also useful as a small array of char. */ + union { + trivial_NFSv4_xattr_buf xattr; + char ch[sizeof (trivial_NFSv4_xattr_buf)]; + } stackbuf; + + char *listbuf = stackbuf.ch; + ssize_t listbufsize = sizeof stackbuf.ch; + char *heapbuf = NULL; + ssize_t listsize; + + /* Use listxattr first, as this means just one syscall in the + typical case where the file lacks an ACL. Try stackbuf + first, falling back on malloc if stackbuf is too small. */ + while ((listsize = listxattr (name, listbuf, listbufsize)) < 0 + && errno == ERANGE) { - ret = getxattr (name, XATTR_NAME_POSIX_ACL_DEFAULT, NULL, 0); - if (ret < 0 && errno == ENODATA) - ret = 0; - else if (ret > 0) - return 1; + free (heapbuf); + listbufsize = listxattr (name, NULL, 0); + if (listbufsize < 0) + return -1; + if (SIZE_MAX < listbufsize) + { + errno = ENOMEM; + return -1; + } + listbuf = heapbuf = malloc (listbufsize); + if (!listbuf) + return -1; } - if (ret < 0) + int ret + = (listsize < 0 ? -1 + : (have_xattr (XATTR_NAME_POSIX_ACL_ACCESS, listbuf, listsize) + || (S_ISDIR (sb->st_mode) + && have_xattr (XATTR_NAME_POSIX_ACL_DEFAULT, + listbuf, listsize)))); + bool nfsv4_acl_but_no_posix_acl + = ret == 0 && have_xattr (XATTR_NAME_NFSV4_ACL, listbuf, listsize); + free (heapbuf); + + /* If there is an NFSv4 ACL but no POSIX ACL, follow up with a + getxattr syscall to see whether the NFSv4 ACL is nontrivial. */ + if (nfsv4_acl_but_no_posix_acl) { - /* Check for NFSv4 ACLs. The max length of a trivial - ACL is 6 words for owner, 6 for group, 7 for everyone, - all times 2 because there are both allow and deny ACEs. - There are 6 words for owner because of type, flag, mask, - wholen, "OWNER@"+pad and similarly for group; everyone is - another word to hold "EVERYONE@". */ - uint32_t xattr[2 * (6 + 6 + 7)]; - - ret = getxattr (name, XATTR_NAME_NFSV4_ACL, xattr, sizeof xattr); + ret = getxattr (name, XATTR_NAME_NFSV4_ACL, + stackbuf.xattr, sizeof stackbuf.xattr); if (ret < 0) switch (errno) { @@ -177,7 +219,7 @@ file_has_acl (char const *name, struct stat const *sb) else { /* It looks like a trivial ACL, but investigate further. */ - ret = acl_nfs4_nontrivial (xattr, ret); + ret = acl_nfs4_nontrivial (stackbuf.xattr, ret); if (ret < 0) { errno = EINVAL; diff --git a/lib/filemode.h b/lib/filemode.h index 15a8dcc3760..3e1d9903eac 100644 --- a/lib/filemode.h +++ b/lib/filemode.h @@ -17,6 +17,12 @@ along with this program. If not, see . */ #ifndef FILEMODE_H_ +# define FILEMODE_H_ + +/* This file uses HAVE_DECL_STRMODE. */ +# if !_GL_CONFIG_H_INCLUDED +# error "Please include config.h first." +# endif # include # include diff --git a/lib/filevercmp.h b/lib/filevercmp.h index 6b81ab32a7f..9e052bdd08c 100644 --- a/lib/filevercmp.h +++ b/lib/filevercmp.h @@ -20,6 +20,11 @@ #ifndef FILEVERCMP_H #define FILEVERCMP_H +/* This file uses _GL_ATTRIBUTE_PURE. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include /* Compare strings A and B as file names containing version numbers, diff --git a/lib/flexmember.h b/lib/flexmember.h index a6cc876a6d5..8c5915ecf9c 100644 --- a/lib/flexmember.h +++ b/lib/flexmember.h @@ -20,6 +20,11 @@ Written by Paul Eggert. */ +/* This file uses _Alignof. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include /* Nonzero multiple of alignment of TYPE, suitable for FLEXSIZEOF below. diff --git a/lib/fpending.h b/lib/fpending.h index 5e860db6810..1604ca0b7af 100644 --- a/lib/fpending.h +++ b/lib/fpending.h @@ -18,6 +18,12 @@ Written by Jim Meyering. */ +/* This file uses _GL_ATTRIBUTE_PURE, HAVE_STDIO_EXT_H, + HAVE_DECL___FPENDING. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include #include #if HAVE_STDIO_EXT_H diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index 47d08a5e27f..29861a31d12 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in @@ -221,6 +221,7 @@ DBUS_LIBS = @DBUS_LIBS@ DBUS_OBJ = @DBUS_OBJ@ DEFS = @DEFS@ DESLIB = @DESLIB@ +DIR_HAS_FD_MEMBER = @DIR_HAS_FD_MEMBER@ DOCMISC_W32 = @DOCMISC_W32@ DUMPING = @DUMPING@ DYNAMIC_LIB_SECONDARY_SUFFIX = @DYNAMIC_LIB_SECONDARY_SUFFIX@ @@ -444,6 +445,7 @@ GL_GNULIB_MBSSEP = @GL_GNULIB_MBSSEP@ GL_GNULIB_MBSSPN = @GL_GNULIB_MBSSPN@ GL_GNULIB_MBSSTR = @GL_GNULIB_MBSSTR@ GL_GNULIB_MBSTOK_R = @GL_GNULIB_MBSTOK_R@ +GL_GNULIB_MBSTOWCS = @GL_GNULIB_MBSTOWCS@ GL_GNULIB_MBTOWC = @GL_GNULIB_MBTOWC@ GL_GNULIB_MDA_ACCESS = @GL_GNULIB_MDA_ACCESS@ GL_GNULIB_MDA_CHDIR = @GL_GNULIB_MDA_CHDIR@ @@ -689,6 +691,7 @@ HAVE_DECL_MEMMEM = @HAVE_DECL_MEMMEM@ HAVE_DECL_MEMRCHR = @HAVE_DECL_MEMRCHR@ HAVE_DECL_OBSTACK_PRINTF = @HAVE_DECL_OBSTACK_PRINTF@ HAVE_DECL_POSIX_SPAWN_SETSID = @HAVE_DECL_POSIX_SPAWN_SETSID@ +HAVE_DECL_PROGRAM_INVOCATION_NAME = @HAVE_DECL_PROGRAM_INVOCATION_NAME@ HAVE_DECL_PUTW = @HAVE_DECL_PUTW@ HAVE_DECL_SETENV = @HAVE_DECL_SETENV@ HAVE_DECL_SETHOSTNAME = @HAVE_DECL_SETHOSTNAME@ @@ -956,6 +959,7 @@ LIB_WSOCK32 = @LIB_WSOCK32@ LIB_XATTR = @LIB_XATTR@ LIMITS_H = @LIMITS_H@ LN_S_FILEONLY = @LN_S_FILEONLY@ +LOCALE_FR_UTF8 = @LOCALE_FR_UTF8@ LTLIBGMP = @LTLIBGMP@ LTLIBINTL = @LTLIBINTL@ LTLIBOBJS = @LTLIBOBJS@ @@ -1127,7 +1131,9 @@ REPLACE_LSEEK = @REPLACE_LSEEK@ REPLACE_LSTAT = @REPLACE_LSTAT@ REPLACE_MALLOC_FOR_MALLOC_GNU = @REPLACE_MALLOC_FOR_MALLOC_GNU@ REPLACE_MALLOC_FOR_MALLOC_POSIX = @REPLACE_MALLOC_FOR_MALLOC_POSIX@ +REPLACE_MBSTOWCS = @REPLACE_MBSTOWCS@ REPLACE_MBTOWC = @REPLACE_MBTOWC@ +REPLACE_MB_CUR_MAX = @REPLACE_MB_CUR_MAX@ REPLACE_MEMCHR = @REPLACE_MEMCHR@ REPLACE_MEMMEM = @REPLACE_MEMMEM@ REPLACE_MEMPCPY = @REPLACE_MEMPCPY@ @@ -1164,6 +1170,7 @@ REPLACE_RAISE = @REPLACE_RAISE@ REPLACE_RANDOM = @REPLACE_RANDOM@ REPLACE_RANDOM_R = @REPLACE_RANDOM_R@ REPLACE_READ = @REPLACE_READ@ +REPLACE_READDIR = @REPLACE_READDIR@ REPLACE_READLINK = @REPLACE_READLINK@ REPLACE_READLINKAT = @REPLACE_READLINKAT@ REPLACE_REALLOCARRAY = @REPLACE_REALLOCARRAY@ @@ -1173,6 +1180,7 @@ REPLACE_REALPATH = @REPLACE_REALPATH@ REPLACE_REMOVE = @REPLACE_REMOVE@ REPLACE_RENAME = @REPLACE_RENAME@ REPLACE_RENAMEAT = @REPLACE_RENAMEAT@ +REPLACE_REWINDDIR = @REPLACE_REWINDDIR@ REPLACE_RMDIR = @REPLACE_RMDIR@ REPLACE_SELECT = @REPLACE_SELECT@ REPLACE_SETENV = @REPLACE_SETENV@ @@ -1732,6 +1740,7 @@ dirent.h: dirent.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ -e 's|@''NEXT_DIRENT_H''@|$(NEXT_DIRENT_H)|g' \ + -e 's/@''DIR_HAS_FD_MEMBER''@/$(DIR_HAS_FD_MEMBER)/g' \ -e 's/@''GNULIB_OPENDIR''@/$(GL_GNULIB_OPENDIR)/g' \ -e 's/@''GNULIB_READDIR''@/$(GL_GNULIB_READDIR)/g' \ -e 's/@''GNULIB_REWINDDIR''@/$(GL_GNULIB_REWINDDIR)/g' \ @@ -1750,6 +1759,8 @@ dirent.h: dirent.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's|@''HAVE_SCANDIR''@|$(HAVE_SCANDIR)|g' \ -e 's|@''HAVE_ALPHASORT''@|$(HAVE_ALPHASORT)|g' \ -e 's|@''REPLACE_OPENDIR''@|$(REPLACE_OPENDIR)|g' \ + -e 's|@''REPLACE_READDIR''@|$(REPLACE_READDIR)|g' \ + -e 's|@''REPLACE_REWINDDIR''@|$(REPLACE_REWINDDIR)|g' \ -e 's|@''REPLACE_CLOSEDIR''@|$(REPLACE_CLOSEDIR)|g' \ -e 's|@''REPLACE_DIRFD''@|$(REPLACE_DIRFD)|g' \ -e 's|@''REPLACE_FDOPENDIR''@|$(REPLACE_FDOPENDIR)|g' \ @@ -1774,6 +1785,8 @@ libgnu_a_SOURCES += dirfd.c endif endif +EXTRA_DIST += dirent-private.h + endif ## end gnulib module dirfd @@ -1974,6 +1987,8 @@ ifneq (,$(GL_COND_OBJ_FDOPENDIR_CONDITION)) libgnu_a_SOURCES += fdopendir.c endif +EXTRA_DIST += dirent-private.h + endif ## end gnulib module fdopendir @@ -3209,6 +3224,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -e 's/@''GNULIB_GRANTPT''@/$(GL_GNULIB_GRANTPT)/g' \ -e 's/@''GNULIB_MALLOC_GNU''@/$(GL_GNULIB_MALLOC_GNU)/g' \ -e 's/@''GNULIB_MALLOC_POSIX''@/$(GL_GNULIB_MALLOC_POSIX)/g' \ + -e 's/@''GNULIB_MBSTOWCS''@/$(GL_GNULIB_MBSTOWCS)/g' \ -e 's/@''GNULIB_MBTOWC''@/$(GL_GNULIB_MBTOWC)/g' \ -e 's/@''GNULIB_MKDTEMP''@/$(GL_GNULIB_MKDTEMP)/g' \ -e 's/@''GNULIB_MKOSTEMP''@/$(GL_GNULIB_MKOSTEMP)/g' \ @@ -3254,6 +3270,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -e 's|@''HAVE_DECL_FCVT''@|$(HAVE_DECL_FCVT)|g' \ -e 's|@''HAVE_DECL_GCVT''@|$(HAVE_DECL_GCVT)|g' \ -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ + -e 's|@''HAVE_DECL_PROGRAM_INVOCATION_NAME''@|$(HAVE_DECL_PROGRAM_INVOCATION_NAME)|g' \ -e 's|@''HAVE_GETPROGNAME''@|$(HAVE_GETPROGNAME)|g' \ -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \ @@ -3302,6 +3319,8 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \ -e 's|@''REPLACE_INITSTATE''@|$(REPLACE_INITSTATE)|g' \ -e 's|@''REPLACE_MALLOC_FOR_MALLOC_GNU''@|$(REPLACE_MALLOC_FOR_MALLOC_GNU)|g' \ -e 's|@''REPLACE_MALLOC_FOR_MALLOC_POSIX''@|$(REPLACE_MALLOC_FOR_MALLOC_POSIX)|g' \ + -e 's|@''REPLACE_MB_CUR_MAX''@|$(REPLACE_MB_CUR_MAX)|g' \ + -e 's|@''REPLACE_MBSTOWCS''@|$(REPLACE_MBSTOWCS)|g' \ -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \ -e 's|@''REPLACE_MKOSTEMP''@|$(REPLACE_MKOSTEMP)|g' \ -e 's|@''REPLACE_MKOSTEMPS''@|$(REPLACE_MKOSTEMPS)|g' \ diff --git a/lib/inttypes.in.h b/lib/inttypes.in.h index 5b7ef12dc7e..22643876ab3 100644 --- a/lib/inttypes.in.h +++ b/lib/inttypes.in.h @@ -46,6 +46,11 @@ #if ! defined INTTYPES_H && ! defined _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H #define INTTYPES_H +/* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* Include or the gnulib replacement. But avoid namespace pollution on glibc systems. */ #ifndef __GLIBC__ diff --git a/lib/limits.in.h b/lib/limits.in.h index a01b4c6a280..45d46fd6897 100644 --- a/lib/limits.in.h +++ b/lib/limits.in.h @@ -99,6 +99,11 @@ # endif #endif +/* Assume no multibyte character is longer than 16 bytes. */ +#ifndef MB_LEN_MAX +# define MB_LEN_MAX 16 +#endif + /* Macros specified by C23 and by ISO/IEC TS 18661-1:2014. */ #if (! defined ULLONG_WIDTH \ diff --git a/lib/malloc/dynarray_emplace_enlarge.c b/lib/malloc/dynarray_emplace_enlarge.c index 7da539316c1..65aabb1e4a5 100644 --- a/lib/malloc/dynarray_emplace_enlarge.c +++ b/lib/malloc/dynarray_emplace_enlarge.c @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include @@ -56,7 +56,7 @@ __libc_dynarray_emplace_enlarge (struct dynarray_header *list, } size_t new_size; - if (INT_MULTIPLY_WRAPV (new_allocated, element_size, &new_size)) + if (ckd_mul (&new_size, new_allocated, element_size)) return false; void *new_array; if (list->array == scratch) diff --git a/lib/malloc/dynarray_resize.c b/lib/malloc/dynarray_resize.c index 7ecd4de63b9..014f98c330e 100644 --- a/lib/malloc/dynarray_resize.c +++ b/lib/malloc/dynarray_resize.c @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include @@ -42,7 +42,7 @@ __libc_dynarray_resize (struct dynarray_header *list, size_t size, over-allocation here. */ size_t new_size_bytes; - if (INT_MULTIPLY_WRAPV (size, element_size, &new_size_bytes)) + if (ckd_mul (&new_size_bytes, size, element_size)) { /* Overflow. */ __set_errno (ENOMEM); diff --git a/lib/md5.h b/lib/md5.h index f34e7cb8dfa..92dc6038988 100644 --- a/lib/md5.h +++ b/lib/md5.h @@ -20,6 +20,11 @@ #ifndef _MD5_H #define _MD5_H 1 +/* This file uses HAVE_OPENSSL_MD5. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include #include diff --git a/lib/minmax.h b/lib/minmax.h index 1fbfc6616cf..0ac40198e24 100644 --- a/lib/minmax.h +++ b/lib/minmax.h @@ -23,6 +23,11 @@ MIN, MAX macro redefinitions on some systems; the workaround is to #include this file as the last one among the #include list. */ +/* This file uses HAVE_MINMAX_IN_LIMITS_H, HAVE_MINMAX_IN_SYS_PARAM_H. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* Before we define the following symbols we get the file since otherwise we get redefinitions on some systems if is included after this file. Likewise for . diff --git a/lib/mktime.c b/lib/mktime.c index 94a4320e6ca..8e80bcdbd16 100644 --- a/lib/mktime.c +++ b/lib/mktime.c @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -379,7 +380,7 @@ __mktime_internal (struct tm *tp, /* Invert CONVERT by probing. First assume the same offset as last time. */ - INT_SUBTRACT_WRAPV (0, off, &negative_offset_guess); + ckd_sub (&negative_offset_guess, 0, off); long_int t0 = ydhms_diff (year, yday, hour, min, sec, EPOCH_YEAR - TM_YEAR_BASE, 0, 0, 0, negative_offset_guess); @@ -465,7 +466,7 @@ __mktime_internal (struct tm *tp, for (direction = -1; direction <= 1; direction += 2) { long_int ot; - if (! INT_ADD_WRAPV (t, delta * direction, &ot)) + if (! ckd_add (&ot, t, delta * direction)) { struct tm otm; if (! ranged_convert (convert, &ot, &otm)) @@ -503,8 +504,8 @@ __mktime_internal (struct tm *tp, /* Set *OFFSET to the low-order bits of T - T0 - NEGATIVE_OFFSET_GUESS. This is just a heuristic to speed up the next mktime call, and correctness is unaffected if integer overflow occurs here. */ - INT_SUBTRACT_WRAPV (t, t0, offset); - INT_SUBTRACT_WRAPV (*offset, negative_offset_guess, offset); + ckd_sub (offset, t, t0); + ckd_sub (offset, *offset, negative_offset_guess); if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec) { @@ -513,7 +514,7 @@ __mktime_internal (struct tm *tp, long_int sec_adjustment = sec == 0 && tm.tm_sec == 60; sec_adjustment -= sec; sec_adjustment += sec_requested; - if (INT_ADD_WRAPV (t, sec_adjustment, &t) + if (ckd_add (&t, t, sec_adjustment) || ! (mktime_min <= t && t <= mktime_max)) { __set_errno (EOVERFLOW); diff --git a/lib/openat.h b/lib/openat.h index 37d8eedbee4..97f066d10f8 100644 --- a/lib/openat.h +++ b/lib/openat.h @@ -19,15 +19,18 @@ #ifndef _GL_HEADER_OPENAT #define _GL_HEADER_OPENAT +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _Noreturn, + _GL_ATTRIBUTE_DEPRECATED, HAVE_OPENAT. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include #include #include #include -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif _GL_INLINE_HEADER_BEGIN #if !HAVE_OPENAT diff --git a/lib/pathmax.h b/lib/pathmax.h index 0dd8f3bc5ce..6930283b82a 100644 --- a/lib/pathmax.h +++ b/lib/pathmax.h @@ -39,6 +39,11 @@ #endif */ +/* This file uses HAVE_SYS_PARAM_H. */ +# if !_GL_CONFIG_H_INCLUDED +# error "Please include config.h first." +# endif + # include # include diff --git a/lib/pselect.c b/lib/pselect.c index f5d21e1048a..52d38378783 100644 --- a/lib/pselect.c +++ b/lib/pselect.c @@ -45,6 +45,12 @@ pselect (int nfds, fd_set *restrict rfds, sigset_t origmask; struct timeval tv, *tvp; + if (nfds < 0 || nfds > FD_SETSIZE) + { + errno = EINVAL; + return -1; + } + if (timeout) { if (! (0 <= timeout->tv_nsec && timeout->tv_nsec < 1000000000)) diff --git a/lib/regex_internal.h b/lib/regex_internal.h index 149ec2e868a..0270091df70 100644 --- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #ifndef _LIBC @@ -822,7 +823,7 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx) } #ifdef _LIBC -# if __GNUC__ >= 7 +# if __glibc_has_attribute (__fallthrough__) # define FALLTHROUGH __attribute__ ((__fallthrough__)) # else # define FALLTHROUGH ((void) 0) diff --git a/lib/regexec.c b/lib/regexec.c index 13e0349e727..f05f38ae0e0 100644 --- a/lib/regexec.c +++ b/lib/regexec.c @@ -324,7 +324,7 @@ re_search_2_stub (struct re_pattern_buffer *bufp, const char *string1, char *s = NULL; if (__glibc_unlikely ((length1 < 0 || length2 < 0 || stop < 0 - || INT_ADD_WRAPV (length1, length2, &len)))) + || ckd_add (&len, length1, length2)))) return -2; /* Concatenate the strings. */ diff --git a/lib/sha1.h b/lib/sha1.h index 5a58b567ceb..854213a9211 100644 --- a/lib/sha1.h +++ b/lib/sha1.h @@ -19,6 +19,11 @@ #ifndef SHA1_H # define SHA1_H 1 +/* This file uses HAVE_OPENSSL_SHA1. */ +# if !_GL_CONFIG_H_INCLUDED +# error "Please include config.h first." +# endif + # include # include diff --git a/lib/sha256.h b/lib/sha256.h index 2879477e89c..938b1067062 100644 --- a/lib/sha256.h +++ b/lib/sha256.h @@ -18,6 +18,11 @@ #ifndef SHA256_H # define SHA256_H 1 +/* This file uses HAVE_OPENSSL_SHA256. */ +# if !_GL_CONFIG_H_INCLUDED +# error "Please include config.h first." +# endif + # include # include diff --git a/lib/sha512.h b/lib/sha512.h index e3a98a2644c..f3465bc8a68 100644 --- a/lib/sha512.h +++ b/lib/sha512.h @@ -18,6 +18,11 @@ #ifndef SHA512_H # define SHA512_H 1 +/* This file uses HAVE_OPENSSL_SHA512. */ +# if !_GL_CONFIG_H_INCLUDED +# error "Please include config.h first." +# endif + # include # include "u64.h" diff --git a/lib/signal.in.h b/lib/signal.in.h index fea12e6572d..418d59c582d 100644 --- a/lib/signal.in.h +++ b/lib/signal.in.h @@ -55,6 +55,11 @@ #ifndef _@GUARD_PREFIX@_SIGNAL_H #define _@GUARD_PREFIX@_SIGNAL_H +/* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* For testing the OpenBSD version. */ #if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \ && defined __OpenBSD__ diff --git a/lib/stat-time.h b/lib/stat-time.h index 92aa1e64e20..5b2702356ee 100644 --- a/lib/stat-time.h +++ b/lib/stat-time.h @@ -20,15 +20,18 @@ #ifndef STAT_TIME_H #define STAT_TIME_H 1 +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_UNUSED, + _GL_ATTRIBUTE_PURE, HAVE_STRUCT_STAT_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include #include #include #include #include -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif _GL_INLINE_HEADER_BEGIN #ifndef _GL_STAT_TIME_INLINE # define _GL_STAT_TIME_INLINE _GL_INLINE diff --git a/lib/stddef.in.h b/lib/stddef.in.h index 6eadcc3d5a4..431e819b8bf 100644 --- a/lib/stddef.in.h +++ b/lib/stddef.in.h @@ -18,7 +18,7 @@ /* Written by Eric Blake. */ /* - * POSIX 2008 for platforms that have issues. + * POSIX 2008 and ISO C 23 for platforms that have issues. * */ @@ -37,9 +37,9 @@ remember if special invocation has ever been used to obtain wint_t, in which case we need to clean up NULL yet again. */ -# if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T) +# if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _@GUARD_PREFIX@_STDDEF_WINT_T) # ifdef __need_wint_t -# define _GL_STDDEF_WINT_T +# define _@GUARD_PREFIX@_STDDEF_WINT_T # endif # @INCLUDE_NEXT@ @NEXT_STDDEF_H@ /* On TinyCC, make sure that the macros that indicate the special invocation @@ -69,6 +69,7 @@ typedef long rpl_max_align_t; typedef long max_align_t; # define _MAX_ALIGN_T # endif +# define __CLANG_MAX_ALIGN_T_DEFINED # define GNULIB_defined_max_align_t 1 # endif # endif @@ -79,7 +80,7 @@ typedef long max_align_t; /* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */ # if (@REPLACE_NULL@ \ - && (!defined _@GUARD_PREFIX@_STDDEF_H || defined _GL_STDDEF_WINT_T)) + && (!defined _@GUARD_PREFIX@_STDDEF_H || defined _@GUARD_PREFIX@_STDDEF_WINT_T)) # undef NULL # ifdef __cplusplus /* ISO C++ says that the macro NULL must expand to an integer constant @@ -100,6 +101,11 @@ typedef long max_align_t; # ifndef _@GUARD_PREFIX@_STDDEF_H # define _@GUARD_PREFIX@_STDDEF_H +/* This file uses _Noreturn. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* Some platforms lack wchar_t. */ #if !@HAVE_WCHAR_T@ # define wchar_t int @@ -137,11 +143,49 @@ typedef union long int __i _GL_STDDEF_ALIGNAS (long int); } rpl_max_align_t; # define max_align_t rpl_max_align_t +# define __CLANG_MAX_ALIGN_T_DEFINED # define GNULIB_defined_max_align_t 1 # endif # endif #endif +/* ISO C 23 § 7.21.1 The unreachable macro */ +#ifndef unreachable + +/* Code borrowed from verify.h. */ +# ifndef _GL_HAS_BUILTIN_UNREACHABLE +# if defined __clang_major__ && __clang_major__ < 5 +# define _GL_HAS_BUILTIN_UNREACHABLE 0 +# elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__) +# define _GL_HAS_BUILTIN_UNREACHABLE 1 +# elif defined __has_builtin +# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable) +# else +# define _GL_HAS_BUILTIN_UNREACHABLE 0 +# endif +# endif + +# if _GL_HAS_BUILTIN_UNREACHABLE +# define unreachable() __builtin_unreachable () +# elif 1200 <= _MSC_VER +# define unreachable() __assume (0) +# else +/* Declare abort(), without including . */ +extern +# if defined __cplusplus +"C" +# endif +_Noreturn +void abort (void) +# if defined __cplusplus && (__GLIBC__ >= 2) +throw () +# endif +; +# define unreachable() abort () +# endif + +#endif + # endif /* _@GUARD_PREFIX@_STDDEF_H */ # endif /* _@GUARD_PREFIX@_STDDEF_H */ #endif /* __need_XXX */ diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 098f841738c..6be12c0525d 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -57,6 +57,12 @@ #ifndef _@GUARD_PREFIX@_STDIO_H #define _@GUARD_PREFIX@_STDIO_H +/* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_FORMAT, + _GL_ATTRIBUTE_MALLOC, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* Get va_list. Needed on many systems, including glibc 2.8. */ #include @@ -127,6 +133,16 @@ # endif #endif +/* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly + allocated memory. */ +#ifndef _GL_ATTRIBUTE_MALLOC +# if __GNUC__ >= 3 || defined __clang__ +# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) +# else +# define _GL_ATTRIBUTE_MALLOC +# endif +#endif + /* An __attribute__ __format__ specifier for a function that takes a format string and arguments, where the format string directives are the ones standardized by ISO C99 and POSIX. @@ -204,6 +220,36 @@ # undef putc_unlocked #endif + +/* Maximum number of characters produced by printing a NaN value. */ +#ifndef _PRINTF_NAN_LEN_MAX +# if defined __FreeBSD__ || defined __DragonFly__ \ + || defined __NetBSD__ \ + || (defined __APPLE__ && defined __MACH__) +/* On BSD systems, a NaN value prints as just "nan", without a sign. */ +# define _PRINTF_NAN_LEN_MAX 3 +# elif (__GLIBC__ >= 2) || MUSL_LIBC || defined __OpenBSD__ || defined __sun || defined __CYGWIN__ +/* glibc, musl libc, OpenBSD, Solaris libc, and Cygwin produce "[-]nan". */ +# define _PRINTF_NAN_LEN_MAX 4 +# elif defined _AIX +/* AIX produces "[-]NaNQ". */ +# define _PRINTF_NAN_LEN_MAX 5 +# elif defined _WIN32 && !defined __CYGWIN__ +/* On native Windows, the output can be: + - with MSVC ucrt: "[-]nan" or "[-]nan(ind)" or "[-]nan(snan)", + - with mingw: "[-]1.#IND" or "[-]1.#QNAN". */ +# define _PRINTF_NAN_LEN_MAX 10 +# elif defined __sgi +/* On IRIX, the output typically is "[-]nan0xNNNNNNNN" with 8 hexadecimal + digits. */ +# define _PRINTF_NAN_LEN_MAX 14 +# else +/* We don't know, but 32 should be a safe maximum. */ +# define _PRINTF_NAN_LEN_MAX 32 +# endif +#endif + + #if @GNULIB_DPRINTF@ # if @REPLACE_DPRINTF@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) @@ -286,7 +332,8 @@ _GL_CXXALIASWARN (fcloseall); # endif _GL_FUNCDECL_RPL (fdopen, FILE *, (int fd, const char *mode) - _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)); + _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1) + _GL_ATTRIBUTE_MALLOC); _GL_CXXALIAS_RPL (fdopen, FILE *, (int fd, const char *mode)); # elif defined _WIN32 && !defined __CYGWIN__ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) @@ -299,7 +346,8 @@ _GL_CXXALIAS_MDA (fdopen, FILE *, (int fd, const char *mode)); /* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose. */ _GL_FUNCDECL_SYS (fdopen, FILE *, (int fd, const char *mode) - _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)); + _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1) + _GL_ATTRIBUTE_MALLOC); # endif _GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode)); # endif @@ -309,7 +357,8 @@ _GL_CXXALIASWARN (fdopen); /* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose. */ _GL_FUNCDECL_SYS (fdopen, FILE *, (int fd, const char *mode) - _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)); + _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1) + _GL_ATTRIBUTE_MALLOC); # endif # if defined GNULIB_POSIXCHECK # undef fdopen @@ -420,7 +469,8 @@ _GL_CXXALIASWARN (fileno); # endif _GL_FUNCDECL_RPL (fopen, FILE *, (const char *restrict filename, const char *restrict mode) - _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)); + _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1) + _GL_ATTRIBUTE_MALLOC); _GL_CXXALIAS_RPL (fopen, FILE *, (const char *restrict filename, const char *restrict mode)); # else @@ -967,6 +1017,10 @@ _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); _GL_CXXALIAS_MDA (getw, int, (FILE *restrict stream)); # else # if @HAVE_DECL_GETW@ +# if defined __APPLE__ && defined __MACH__ +/* The presence of the declaration depends on _POSIX_C_SOURCE. */ +_GL_FUNCDECL_SYS (getw, int, (FILE *restrict stream)); +# endif _GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream)); # endif # endif @@ -1071,13 +1125,15 @@ _GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - " # endif _GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode) - _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1)); + _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1) + _GL_ATTRIBUTE_MALLOC); _GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode)); # else # if !@HAVE_POPEN@ || __GNUC__ >= 11 _GL_FUNCDECL_SYS (popen, FILE *, (const char *cmd, const char *mode) - _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1)); + _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1) + _GL_ATTRIBUTE_MALLOC); # endif _GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode)); # endif @@ -1087,7 +1143,8 @@ _GL_CXXALIASWARN (popen); /* For -Wmismatched-dealloc: Associate popen with pclose or rpl_pclose. */ _GL_FUNCDECL_SYS (popen, FILE *, (const char *cmd, const char *mode) - _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1)); + _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1) + _GL_ATTRIBUTE_MALLOC); # endif # if defined GNULIB_POSIXCHECK # undef popen @@ -1210,6 +1267,10 @@ _GL_CXXALIASWARN (puts); _GL_CXXALIAS_MDA (putw, int, (int w, FILE *restrict stream)); # else # if @HAVE_DECL_PUTW@ +# if defined __APPLE__ && defined __MACH__ +/* The presence of the declaration depends on _POSIX_C_SOURCE. */ +_GL_FUNCDECL_SYS (putw, int, (int w, FILE *restrict stream)); +# endif _GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream)); # endif # endif @@ -1421,13 +1482,15 @@ _GL_CXXALIASWARN (tempnam); # define tmpfile rpl_tmpfile # endif _GL_FUNCDECL_RPL (tmpfile, FILE *, (void) - _GL_ATTRIBUTE_DEALLOC (fclose, 1)); + _GL_ATTRIBUTE_DEALLOC (fclose, 1) + _GL_ATTRIBUTE_MALLOC); _GL_CXXALIAS_RPL (tmpfile, FILE *, (void)); # else # if __GNUC__ >= 11 /* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose. */ _GL_FUNCDECL_SYS (tmpfile, FILE *, (void) - _GL_ATTRIBUTE_DEALLOC (fclose, 1)); + _GL_ATTRIBUTE_DEALLOC (fclose, 1) + _GL_ATTRIBUTE_MALLOC); # endif _GL_CXXALIAS_SYS (tmpfile, FILE *, (void)); # endif @@ -1438,7 +1501,8 @@ _GL_CXXALIASWARN (tmpfile); # if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined tmpfile /* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose. */ _GL_FUNCDECL_SYS (tmpfile, FILE *, (void) - _GL_ATTRIBUTE_DEALLOC (fclose, 1)); + _GL_ATTRIBUTE_DEALLOC (fclose, 1) + _GL_ATTRIBUTE_MALLOC); # endif # if defined GNULIB_POSIXCHECK # undef tmpfile diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index a91f4e23d67..1479a2b2871 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -37,6 +37,12 @@ #ifndef _@GUARD_PREFIX@_STDLIB_H #define _@GUARD_PREFIX@_STDLIB_H +/* This file uses _Noreturn, _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC, + _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* NetBSD 5.0 mis-defines NULL. */ #include @@ -67,9 +73,7 @@ # include # endif -# if !@HAVE_STRUCT_RANDOM_DATA@ || @REPLACE_RANDOM_R@ || !@HAVE_RANDOM_R@ -# include -# endif +# include # if !@HAVE_STRUCT_RANDOM_DATA@ /* Define 'struct random_data'. @@ -461,7 +465,7 @@ _GL_WARN_ON_USE (getloadavg, "getloadavg is not portable - " # undef getprogname # define getprogname rpl_getprogname # endif -# ifdef HAVE_DECL_PROGRAM_INVOCATION_NAME +# if @HAVE_DECL_PROGRAM_INVOCATION_NAME@ _GL_FUNCDECL_RPL (getprogname, const char *, (void) _GL_ATTRIBUTE_PURE); # else _GL_FUNCDECL_RPL (getprogname, const char *, (void)); @@ -469,7 +473,7 @@ _GL_FUNCDECL_RPL (getprogname, const char *, (void)); _GL_CXXALIAS_RPL (getprogname, const char *, (void)); # else # if !@HAVE_GETPROGNAME@ -# ifdef HAVE_DECL_PROGRAM_INVOCATION_NAME +# if @HAVE_DECL_PROGRAM_INVOCATION_NAME@ _GL_FUNCDECL_SYS (getprogname, const char *, (void) _GL_ATTRIBUTE_PURE); # else _GL_FUNCDECL_SYS (getprogname, const char *, (void)); @@ -589,6 +593,51 @@ _GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - " # endif #endif +/* Return maximum number of bytes of a multibyte character. */ +#if @REPLACE_MB_CUR_MAX@ +# if !GNULIB_defined_MB_CUR_MAX +static inline +int gl_MB_CUR_MAX (void) +{ + /* Turn the value 3 to the value 4, as needed for the UTF-8 encoding. */ + return MB_CUR_MAX + (MB_CUR_MAX == 3); +} +# undef MB_CUR_MAX +# define MB_CUR_MAX gl_MB_CUR_MAX () +# define GNULIB_defined_MB_CUR_MAX 1 +# endif +#endif + +/* Convert a string to a wide string. */ +#if @GNULIB_MBSTOWCS@ +# if @REPLACE_MBSTOWCS@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mbstowcs +# define mbstowcs rpl_mbstowcs +# endif +_GL_FUNCDECL_RPL (mbstowcs, size_t, + (wchar_t *restrict dest, const char *restrict src, + size_t len) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (mbstowcs, size_t, + (wchar_t *restrict dest, const char *restrict src, + size_t len)); +# else +_GL_CXXALIAS_SYS (mbstowcs, size_t, + (wchar_t *restrict dest, const char *restrict src, + size_t len)); +# endif +# if __GLIBC__ >= 2 +_GL_CXXALIASWARN (mbstowcs); +# endif +#elif defined GNULIB_POSIXCHECK +# undef mbstowcs +# if HAVE_RAW_DECL_MBSTOWCS +_GL_WARN_ON_USE (mbstowcs, "mbstowcs is unportable - " + "use gnulib module mbstowcs for portability"); +# endif +#endif + /* Convert a multibyte character to a wide character. */ #if @GNULIB_MBTOWC@ # if @REPLACE_MBTOWC@ @@ -1009,7 +1058,9 @@ _GL_FUNCDECL_SYS (random, long, (void)); int. */ _GL_CXXALIAS_SYS_CAST (random, long, (void)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (random); +# endif #elif defined GNULIB_POSIXCHECK # undef random # if HAVE_RAW_DECL_RANDOM @@ -1034,7 +1085,9 @@ _GL_FUNCDECL_SYS (srandom, void, (unsigned int seed)); unsigned long seed. */ _GL_CXXALIAS_SYS_CAST (srandom, void, (unsigned int seed)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (srandom); +# endif #elif defined GNULIB_POSIXCHECK # undef srandom # if HAVE_RAW_DECL_SRANDOM diff --git a/lib/string.in.h b/lib/string.in.h index b6bf432e1f1..912d0f7a306 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -44,6 +44,12 @@ #ifndef _@GUARD_PREFIX@_STRING_H #define _@GUARD_PREFIX@_STRING_H +/* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC, + _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* NetBSD 5.0 mis-defines NULL. */ #include diff --git a/lib/strtol.c b/lib/strtol.c index d11269b2622..b93483dca49 100644 --- a/lib/strtol.c +++ b/lib/strtol.c @@ -288,6 +288,11 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, s += 2; base = 16; } + else if ((base == 0 || base == 2) && TOUPPER (s[1]) == L_('B')) + { + s += 2; + base = 2; + } else if (base == 0) base = 8; } @@ -378,11 +383,14 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, noconv: /* We must handle a special case here: the base is 0 or 16 and the first two characters are '0' and 'x', but the rest are no - hexadecimal digits. This is no error case. We return 0 and - ENDPTR points to the 'x'. */ + hexadecimal digits. Likewise when the base is 0 or 2 and the + first two characters are '0' and 'b', but the rest are no binary + digits. This is no error case. We return 0 and ENDPTR points to + the 'x' or 'b'. */ if (endptr != NULL) { - if (save - nptr >= 2 && TOUPPER (save[-1]) == L_('X') + if (save - nptr >= 2 + && (TOUPPER (save[-1]) == L_('X') || TOUPPER (save[-1]) == L_('B')) && save[-2] == L_('0')) *endptr = (STRING_TYPE *) &save[-1]; else diff --git a/lib/sys_random.in.h b/lib/sys_random.in.h index 8dca1326837..b240033bcbf 100644 --- a/lib/sys_random.in.h +++ b/lib/sys_random.in.h @@ -45,6 +45,11 @@ #ifndef _@GUARD_PREFIX@_SYS_RANDOM_H #define _@GUARD_PREFIX@_SYS_RANDOM_H +/* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include /* Define the GRND_* constants. */ diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h index 13440fa6f0a..3abfc48af09 100644 --- a/lib/sys_select.in.h +++ b/lib/sys_select.in.h @@ -19,6 +19,13 @@ # endif @PRAGMA_COLUMNS@ +/* This file uses #include_next of a system file that defines time_t. + For the 'year2038' module to work right, needs to have been + included before. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* On OSF/1 and Solaris 2.6, and both include . On Cygwin and OpenBSD, includes . @@ -71,6 +78,11 @@ #ifndef _@GUARD_PREFIX@_SYS_SELECT_H +/* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* On many platforms, assumes prior inclusion of . Also, mingw defines sigset_t there, instead of in where it belongs. */ diff --git a/lib/sys_stat.in.h b/lib/sys_stat.in.h index 0c2f39c12bf..ad4da17fa46 100644 --- a/lib/sys_stat.in.h +++ b/lib/sys_stat.in.h @@ -25,6 +25,13 @@ #endif @PRAGMA_COLUMNS@ +/* This file uses #include_next of a system file that defines time_t. + For the 'year2038' module to work right, needs to have been + included before. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #if defined __need_system_sys_stat_h /* Special invocation convention. */ @@ -48,6 +55,11 @@ #ifndef _@GUARD_PREFIX@_SYS_STAT_H #define _@GUARD_PREFIX@_SYS_STAT_H +/* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ /* The definition of _GL_ARG_NONNULL is copied here. */ diff --git a/lib/sys_time.in.h b/lib/sys_time.in.h index e833d551677..59cce1440da 100644 --- a/lib/sys_time.in.h +++ b/lib/sys_time.in.h @@ -24,6 +24,13 @@ #endif @PRAGMA_COLUMNS@ +/* This file uses #include_next of a system file that defines time_t. + For the 'year2038' module to work right, needs to have been + included before. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* On Cygwin and on many BSDish systems, includes itself recursively via . Simply delegate to the system's header in this case; it is a no-op. @@ -41,6 +48,11 @@ #ifndef _@GUARD_PREFIX@_SYS_TIME_H #define _@GUARD_PREFIX@_SYS_TIME_H +/* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #if ! @HAVE_SYS_TIME_H@ # include #endif diff --git a/lib/sys_types.in.h b/lib/sys_types.in.h index 082a6c674de..ea77e140be9 100644 --- a/lib/sys_types.in.h +++ b/lib/sys_types.in.h @@ -20,6 +20,13 @@ #endif @PRAGMA_COLUMNS@ +/* This file uses #include_next of a system file that defines time_t. + For the 'year2038' module to work right, needs to have been + included before. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #if defined _WIN32 && !defined __CYGWIN__ \ && (defined __need_off_t || defined __need___off64_t \ || defined __need_ssize_t || defined __need_time_t) diff --git a/lib/time.in.h b/lib/time.in.h index 3f9af920e34..06428adb1d0 100644 --- a/lib/time.in.h +++ b/lib/time.in.h @@ -20,6 +20,13 @@ #endif @PRAGMA_COLUMNS@ +/* This file uses #include_next of a system file that defines time_t. + For the 'year2038' module to work right, needs to have been + included before. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* Don't get in the way of glibc when it includes time.h merely to declare a few standard symbols, rather than to declare all the symbols. (However, skip this for MinGW as it treats __need_time_t @@ -45,6 +52,12 @@ # @INCLUDE_NEXT@ @NEXT_TIME_H@ +/* This file uses _GL_ATTRIBUTE_DEPRECATED, GNULIB_POSIXCHECK, + HAVE_RAW_DECL_*. */ +# if !_GL_CONFIG_H_INCLUDED +# error "Please include config.h first." +# endif + /* NetBSD 5.0 mis-defines NULL. */ # include @@ -154,7 +167,9 @@ _GL_CXXALIAS_RPL (time, time_t, (time_t *__tp)); # else _GL_CXXALIAS_SYS (time, time_t, (time_t *__tp)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (time); +# endif # endif /* Sleep for at least RQTP seconds unless interrupted, If interrupted, @@ -341,7 +356,9 @@ _GL_CXXALIASWARN (strptime); # if !(defined __cplusplus && defined GNULIB_NAMESPACE) # define ctime rpl_ctime # endif +# ifndef __cplusplus _GL_ATTRIBUTE_DEPRECATED +# endif _GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp) _GL_ARG_NONNULL ((1))); _GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp)); diff --git a/lib/timespec.h b/lib/timespec.h index ba78647f09a..0bdfd76ef78 100644 --- a/lib/timespec.h +++ b/lib/timespec.h @@ -19,11 +19,14 @@ #if ! defined TIMESPEC_H #define TIMESPEC_H -#include - -#ifndef _GL_INLINE_HEADER_BEGIN +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_ATTRIBUTE_CONST, + _GL_ATTRIBUTE_PURE, _GL_CMP. */ +#if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." #endif + +#include + _GL_INLINE_HEADER_BEGIN #ifndef _GL_TIMESPEC_INLINE # define _GL_TIMESPEC_INLINE _GL_INLINE diff --git a/lib/u64.h b/lib/u64.h index 0353ad4d9af..8a99335b6aa 100644 --- a/lib/u64.h +++ b/lib/u64.h @@ -17,11 +17,13 @@ /* Written by Paul Eggert. */ -#include - -#ifndef _GL_INLINE_HEADER_BEGIN +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */ +#if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." #endif + +#include + _GL_INLINE_HEADER_BEGIN #ifndef _GL_U64_INLINE # define _GL_U64_INLINE _GL_INLINE diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 8ba9867894e..2ae040a76b3 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -69,6 +69,12 @@ #if !defined _@GUARD_PREFIX@_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H #define _@GUARD_PREFIX@_UNISTD_H +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, GNULIB_POSIXCHECK, + HAVE_RAW_DECL_*. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + /* NetBSD 5.0 mis-defines NULL. Also get size_t. */ /* But avoid namespace pollution on glibc systems. */ #ifndef __GLIBC__ @@ -170,9 +176,6 @@ # include #endif -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif _GL_INLINE_HEADER_BEGIN #ifndef _GL_UNISTD_INLINE # define _GL_UNISTD_INLINE _GL_INLINE diff --git a/lib/unlocked-io.h b/lib/unlocked-io.h index fdef624ab9c..4830df4a747 100644 --- a/lib/unlocked-io.h +++ b/lib/unlocked-io.h @@ -31,6 +31,11 @@ the *_unlocked functions directly. On hosts that lack those functions, invoke the non-thread-safe versions instead. */ +/* This file uses HAVE_DECL_*_UNLOCKED. */ +# if !_GL_CONFIG_H_INCLUDED +# error "Please include config.h first." +# endif + # include # if HAVE_DECL_CLEARERR_UNLOCKED || defined clearerr_unlocked diff --git a/lib/utimens.h b/lib/utimens.h index a7056981f32..4a21792a7e4 100644 --- a/lib/utimens.h +++ b/lib/utimens.h @@ -17,6 +17,11 @@ /* Written by Paul Eggert. */ +/* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + #include int fdutimens (int, char const *, struct timespec const [2]); int utimens (char const *, struct timespec const [2]); @@ -26,9 +31,6 @@ int lutimens (char const *, struct timespec const [2]); # include # include -#ifndef _GL_INLINE_HEADER_BEGIN - #error "Please include config.h first." -#endif _GL_INLINE_HEADER_BEGIN #ifndef _GL_UTIMENS_INLINE # define _GL_UTIMENS_INLINE _GL_INLINE diff --git a/lib/verify.h b/lib/verify.h index f0b3fc5851b..e4af91517e6 100644 --- a/lib/verify.h +++ b/lib/verify.h @@ -241,10 +241,16 @@ template # define _Static_assert(...) \ _GL_VERIFY (__VA_ARGS__, "static assertion failed", -) # else - /* Work around MSVC preprocessor incompatibility with ISO C; see - . */ -# define _Static_assert(R, ...) \ - _GL_VERIFY ((R), "static assertion failed", -) +# if defined __cplusplus && _MSC_VER >= 1910 + /* In MSVC 14.1 or newer, static_assert accepts one or two arguments, + but _Static_assert is not defined. */ +# define _Static_assert static_assert +# else + /* Work around MSVC preprocessor incompatibility with ISO C; see + . */ +# define _Static_assert(R, ...) \ + _GL_VERIFY ((R), "static assertion failed", -) +# endif # endif # endif /* Define static_assert if needed. */ @@ -252,7 +258,7 @@ template && __STDC_VERSION__ < 202311 \ && (!defined __cplusplus \ || (__cpp_static_assert < 201411 \ - && __GNUG__ < 6 && __clang_major__ < 6))) + && __GNUG__ < 6 && __clang_major__ < 6 && _MSC_VER < 1910))) # if defined __cplusplus && _MSC_VER >= 1900 && !defined __clang__ /* MSVC 14 in C++ mode supports the two-arguments static_assert but not the one-argument static_assert, and it does not support _Static_assert. @@ -285,14 +291,16 @@ template # define _GL_HAS_BUILTIN_TRAP 0 #endif -#if defined __clang_major__ && __clang_major__ < 5 -# define _GL_HAS_BUILTIN_UNREACHABLE 0 -#elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__) -# define _GL_HAS_BUILTIN_UNREACHABLE 1 -#elif defined __has_builtin -# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable) -#else -# define _GL_HAS_BUILTIN_UNREACHABLE 0 +#ifndef _GL_HAS_BUILTIN_UNREACHABLE +# if defined __clang_major__ && __clang_major__ < 5 +# define _GL_HAS_BUILTIN_UNREACHABLE 0 +# elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__) +# define _GL_HAS_BUILTIN_UNREACHABLE 1 +# elif defined __has_builtin +# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable) +# else +# define _GL_HAS_BUILTIN_UNREACHABLE 0 +# endif #endif /* Each of these macros verifies that its argument R is nonzero. To -- cgit v1.2.3 From 3cd8ce87d298c3e0ca1e2336400d06c1a8794381 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 14 May 2023 18:51:23 -0700 Subject: Work after 2038 on 32-bit GNU/Linux This adds support for 64-bit time_t on 32-bit GNU/Linux ARM and x86, where time_t was historically 32-bit. The resulting Emacs should continue to work for timestamps after mid-January 2038. * admin/merge-gnulib (GNULIB_MODULES): Add year2038. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. --- admin/merge-gnulib | 2 +- lib/gnulib.mk.in | 3 ++- m4/gnulib-comp.m4 | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/admin/merge-gnulib b/admin/merge-gnulib index 7c82be98608..97487381886 100755 --- a/admin/merge-gnulib +++ b/admin/merge-gnulib @@ -48,7 +48,7 @@ GNULIB_MODULES=' stpcpy strnlen strtoimax symlink sys_stat sys_time tempname time-h time_r time_rz timegm timer-time timespec-add timespec-sub update-copyright unlocked-io utimensat - vla warnings + vla warnings year2038 ' AVOIDED_MODULES=' diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index 29861a31d12..5722e2588eb 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in @@ -167,7 +167,8 @@ # update-copyright \ # utimensat \ # vla \ -# warnings +# warnings \ +# year2038 MOSTLYCLEANFILES += core *.stackdump diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index 58fcd1c0481..882b5869755 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -210,6 +210,8 @@ AC_DEFUN([gl_EARLY], # Code from module vla: # Code from module warnings: # Code from module xalloc-oversized: + # Code from module year2038: + AC_REQUIRE([AC_SYS_YEAR2038]) ]) # This macro should be invoked from ./configure.ac, in the section -- cgit v1.2.3