commit 41ffeaec15b9a0f052de2d2e5eab23302c4ce46b Author: Paul Eggert Date: Fri Dec 12 15:24:31 2025 -0800 Update from Gnulib by running admin/merge-gnulib diff --git a/lib/acl-internal.c b/lib/acl-internal.c index 7d7cbb79818..413be44e6e1 100644 --- a/lib/acl-internal.c +++ b/lib/acl-internal.c @@ -17,10 +17,10 @@ Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible. */ +#define ACL_INTERNAL_INLINE _GL_EXTERN_INLINE #include /* Specification. */ -#define ACL_INTERNAL_INLINE _GL_EXTERN_INLINE #include "acl-internal.h" #include "acl.h" @@ -237,9 +237,8 @@ acl_ace_nontrivial (int count, ace_t *entries) for (int i = 0; i < count; i++) { ace_t *ace = &entries[i]; - unsigned int index1; - unsigned int index2; + unsigned int index1; if (ace->a_type == NEW_ACE_ACCESS_ALLOWED_ACE_TYPE) index1 = 1; else if (ace->a_type == NEW_ACE_ACCESS_DENIED_ACE_TYPE) @@ -247,6 +246,7 @@ acl_ace_nontrivial (int count, ace_t *entries) else return 1; + unsigned int index2; if (ace->a_flags == NEW_ACE_OWNER) index2 = 0; else if (ace->a_flags == (NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP)) diff --git a/lib/at-func.c b/lib/at-func.c index fc433a45e4c..b61d5ec3749 100644 --- a/lib/at-func.c +++ b/lib/at-func.c @@ -78,12 +78,8 @@ AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS) errno = ENOTSUP; return FUNC_FAIL; #else - { - /* Be careful to choose names unlikely to conflict with + /* Be careful to choose variable names unlikely to conflict with AT_FUNC_POST_FILE_PARAM_DECLS. */ - struct saved_cwd saved_cwd; - int saved_errno; - FUNC_RESULT err; { char proc_buf[OPENAT_BUFFER_SIZE]; @@ -107,6 +103,7 @@ AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS) } } + struct saved_cwd saved_cwd; if (save_cwd (&saved_cwd) != 0) openat_save_fail (errno); if (0 <= fd && fd == saved_cwd.desc) @@ -121,14 +118,14 @@ AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS) if (fchdir (fd) != 0) { - saved_errno = errno; + int saved_errno = errno; free_cwd (&saved_cwd); errno = saved_errno; return FUNC_FAIL; } - err = CALL_FUNC (file); - saved_errno = (err == FUNC_FAIL ? errno : 0); + FUNC_RESULT err = CALL_FUNC (file); + int saved_errno = (err == FUNC_FAIL ? errno : 0); if (restore_cwd (&saved_cwd) != 0) openat_restore_fail (errno); @@ -138,7 +135,6 @@ AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS) if (saved_errno) errno = saved_errno; return err; - } #endif } #undef CALL_FUNC diff --git a/lib/binary-io.c b/lib/binary-io.c index d2937b8f63b..bc096a861d6 100644 --- a/lib/binary-io.c +++ b/lib/binary-io.c @@ -14,9 +14,8 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define BINARY_IO_INLINE _GL_EXTERN_INLINE +#include #include "binary-io.h" #if defined __DJGPP__ || defined __EMX__ diff --git a/lib/boot-time-aux.h b/lib/boot-time-aux.h index f1f940b12e4..af28ea6db42 100644 --- a/lib/boot-time-aux.h +++ b/lib/boot-time-aux.h @@ -395,13 +395,15 @@ get_windows_boot_time_fallback (struct timespec *p_boot_time) if (GetTickCount64Func != NULL) { ULONGLONG uptime_ms = GetTickCount64Func (); - struct timespec uptime; - struct timespec result; + struct timeval tv; if (gettimeofday (&tv, NULL) >= 0) { + struct timespec uptime; uptime.tv_sec = uptime_ms / 1000; uptime.tv_nsec = (uptime_ms % 1000) * 1000000; + + struct timespec result; result.tv_sec = tv.tv_sec; result.tv_nsec = tv.tv_usec * 1000; if (result.tv_nsec < uptime.tv_nsec) @@ -411,6 +413,7 @@ get_windows_boot_time_fallback (struct timespec *p_boot_time) } result.tv_sec -= uptime.tv_sec; result.tv_nsec -= uptime.tv_nsec; + *p_boot_time = result; return 0; } diff --git a/lib/byteswap.c b/lib/byteswap.c index 97f7fc9ebfd..0b5b8884420 100644 --- a/lib/byteswap.c +++ b/lib/byteswap.c @@ -15,7 +15,6 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define _GL_BYTESWAP_INLINE _GL_EXTERN_INLINE +#include #include diff --git a/lib/c-ctype.c b/lib/c-ctype.c index ecf2c083209..960155f3f3e 100644 --- a/lib/c-ctype.c +++ b/lib/c-ctype.c @@ -15,7 +15,6 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define C_CTYPE_INLINE _GL_EXTERN_INLINE +#include #include "c-ctype.h" diff --git a/lib/c-strcasecmp.c b/lib/c-strcasecmp.c index 2d963c30e98..5e7dd41836f 100644 --- a/lib/c-strcasecmp.c +++ b/lib/c-strcasecmp.c @@ -28,29 +28,24 @@ c_strcasecmp (const char *s1, const char *s2) { register const unsigned char *p1 = (const unsigned char *) s1; register const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; if (p1 == p2) return 0; - do + for (;; p1++, p2++) { - c1 = c_tolower (*p1); - c2 = c_tolower (*p2); - - if (c1 == '\0') - break; - - ++p1; - ++p2; + unsigned char c1 = c_tolower (*p1); + unsigned char c2 = c_tolower (*p2); + + if (c1 == '\0' || c1 != c2) + { + if (UCHAR_MAX <= INT_MAX) + return c1 - c2; + else + /* On machines where 'char' and 'int' are types of the same size, + the difference of two 'unsigned char' values - including the + sign bit - doesn't fit in an 'int'. */ + return _GL_CMP (c1, c2); + } } - while (c1 == c2); - - if (UCHAR_MAX <= INT_MAX) - return c1 - c2; - else - /* On machines where 'char' and 'int' are types of the same size, the - difference of two 'unsigned char' values - including the sign bit - - doesn't fit in an 'int'. */ - return _GL_CMP (c1, c2); } diff --git a/lib/c-strncasecmp.c b/lib/c-strncasecmp.c index 6da59d09b32..0409e19a98f 100644 --- a/lib/c-strncasecmp.c +++ b/lib/c-strncasecmp.c @@ -28,29 +28,24 @@ c_strncasecmp (const char *s1, const char *s2, size_t n) { register const unsigned char *p1 = (const unsigned char *) s1; register const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; if (p1 == p2 || n == 0) return 0; - do + for (;; p1++, p2++) { - c1 = c_tolower (*p1); - c2 = c_tolower (*p2); - - if (--n == 0 || c1 == '\0') - break; - - ++p1; - ++p2; + unsigned char c1 = c_tolower (*p1); + unsigned char c2 = c_tolower (*p2); + + if (--n == 0 || c1 == '\0' || c1 != c2) + { + if (UCHAR_MAX <= INT_MAX) + return c1 - c2; + else + /* On machines where 'char' and 'int' are types of the same size, + the difference of two 'unsigned char' values - including the + sign bit - doesn't fit in an 'int'. */ + return _GL_CMP (c1, c2); + } } - while (c1 == c2); - - if (UCHAR_MAX <= INT_MAX) - return c1 - c2; - else - /* On machines where 'char' and 'int' are types of the same size, the - difference of two 'unsigned char' values - including the sign bit - - doesn't fit in an 'int'. */ - return _GL_CMP (c1, c2); } diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index 7aea4aaba61..ed89ec4f679 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -191,11 +191,6 @@ struct realpath_bufs static char * realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs) { - char *dest; - char const *start; - char const *end; - int num_links = 0; - if (name == NULL) { /* As per Single Unix Specification V2 we must return an error if @@ -215,12 +210,15 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs) } char *rname = bufs->rname.data; - bool end_in_extra_buffer = false; - bool failed = true; /* This is always zero for Posix hosts, but can be 2 for MS-Windows and MS-DOS X:/foo/bar file names. */ - idx_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name); + idx_t prefix_len; + + char *dest; + char const *start; + + bool failed = true; if (!IS_ABSOLUTE_FILE_NAME (name)) { @@ -241,6 +239,7 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs) } else { + prefix_len = FILE_SYSTEM_PREFIX_LEN (name); dest = __mempcpy (rname, name, prefix_len); *dest++ = '/'; if (DOUBLE_SLASH_IS_DISTINCT_ROOT) @@ -253,13 +252,17 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs) start = name + prefix_len; } - for ( ; *start; start = end) + int num_links = 0; + bool end_in_extra_buffer = false; + + for (; *start;) { /* Skip sequence of multiple file name separators. */ while (ISSLASH (*start)) ++start; /* Find end of component. */ + char const *end; for (end = start; *end && !ISSLASH (*end); ++end) /* Nothing. */; @@ -378,6 +381,8 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs) : errno == EINVAL)) goto error; } + + start = end; } if (dest > rname + prefix_len + 1 && ISSLASH (dest[-1])) --dest; diff --git a/lib/dup2.c b/lib/dup2.c index 434e78c2bc6..65a43087c02 100644 --- a/lib/dup2.c +++ b/lib/dup2.c @@ -70,8 +70,6 @@ dup2_nothrow (int fd, int desired_fd) static int ms_windows_dup2 (int fd, int desired_fd) { - int result; - /* If fd is closed, mingw hangs on dup2 (fd, fd). If fd is open, dup2 (fd, fd) returns 0, but all further attempts to use fd in future dup2 calls will hang. */ @@ -93,7 +91,7 @@ ms_windows_dup2 (int fd, int desired_fd) return -1; } - result = dup2_nothrow (fd, desired_fd); + int result = dup2_nothrow (fd, desired_fd); if (result == 0) result = desired_fd; @@ -110,10 +108,7 @@ ms_windows_dup2 (int fd, int desired_fd) static int klibc_dup2dirfd (int fd, int desired_fd) { - int tempfd; - int dupfd; - - tempfd = open ("NUL", O_RDONLY); + int tempfd = open ("NUL", O_RDONLY); if (tempfd < 0) return tempfd; @@ -129,7 +124,7 @@ klibc_dup2dirfd (int fd, int desired_fd) { close (desired_fd); - dupfd = open (path, O_RDONLY); + int dupfd = open (path, O_RDONLY); if (dupfd < 0) return dupfd; @@ -150,7 +145,7 @@ klibc_dup2dirfd (int fd, int desired_fd) } } - dupfd = klibc_dup2dirfd (fd, desired_fd); + int dupfd = klibc_dup2dirfd (fd, desired_fd); close (tempfd); @@ -160,13 +155,17 @@ klibc_dup2dirfd (int fd, int desired_fd) static int klibc_dup2 (int fd, int desired_fd) { - int dupfd; - struct stat sbuf; + int dupfd = dup2 (fd, desired_fd); + if (dupfd < 0 && errno == ENOTSUP) + { + struct stat sbuf; + if (!fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode)) + { + close (desired_fd); - dupfd = dup2 (fd, desired_fd); - if (dupfd < 0 && errno == ENOTSUP \ - && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode)) - return klibc_dup2dirfd (fd, desired_fd); + return klibc_dup2dirfd (fd, desired_fd); + } + } return dupfd; } @@ -177,8 +176,6 @@ klibc_dup2 (int fd, int desired_fd) int rpl_dup2 (int fd, int desired_fd) { - int result; - #ifdef F_GETFL /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF. On Cygwin 1.5.x, dup2 (1, 1) returns 0. @@ -194,7 +191,7 @@ rpl_dup2 (int fd, int desired_fd) return fcntl (fd, F_GETFL) == -1 ? -1 : fd; #endif - result = dup2 (fd, desired_fd); + int result = dup2 (fd, desired_fd); /* Correct an errno value on FreeBSD 6.1 and Cygwin 1.5.x. */ if (result < 0 && errno == EMFILE) diff --git a/lib/endian.c b/lib/endian.c index 702f7e0d697..bfa551d6da4 100644 --- a/lib/endian.c +++ b/lib/endian.c @@ -19,5 +19,4 @@ #define _GL_ENDIAN_INLINE _GL_EXTERN_INLINE #include - #include diff --git a/lib/euidaccess.c b/lib/euidaccess.c index 67b9a94544f..78610402dd6 100644 --- a/lib/euidaccess.c +++ b/lib/euidaccess.c @@ -111,16 +111,13 @@ euidaccess (const char *file, int mode) } else { - int result; - int saved_errno; - if (uid != euid) setreuid (euid, uid); if (gid != egid) setregid (egid, gid); - result = access (file, mode); - saved_errno = errno; + int result = access (file, mode); + int saved_errno = errno; /* Restore them. */ if (uid != euid) @@ -138,7 +135,6 @@ euidaccess (const char *file, int mode) correct on systems that have ACLs or the like. However, it's better than nothing, and it is reentrant. */ - unsigned int granted; if (uid == euid && gid == egid) /* If we are not set-uid or set-gid, access does the same. */ return access (file, mode); @@ -165,6 +161,7 @@ euidaccess (const char *file, int mode) return 0; /* The file exists. */ /* Convert the file's permission bits to traditional form. */ + unsigned int granted; if (S_IRUSR == (4 << 6) && S_IWUSR == (2 << 6) && S_IXUSR == (1 << 6) && S_IRGRP == (4 << 3) && S_IWGRP == (2 << 3) && S_IXGRP == (1 << 3) && S_IROTH == (4 << 0) && S_IWOTH == (2 << 0) && S_IXOTH == (1 << 0)) @@ -206,16 +203,12 @@ weak_alias (__euidaccess, euidaccess) int main (int argc, char **argv) { - char *file; - int mode; - int err; - if (argc < 3) abort (); - file = argv[1]; - mode = atoi (argv[2]); + char *file = argv[1]; + int mode = atoi (argv[2]); - err = euidaccess (file, mode); + int err = euidaccess (file, mode); printf ("%d\n", err); if (err != 0) error (0, errno, "%s", file); diff --git a/lib/execinfo.c b/lib/execinfo.c index a9fe54075f0..745fbbb052f 100644 --- a/lib/execinfo.c +++ b/lib/execinfo.c @@ -15,7 +15,6 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define _GL_EXECINFO_INLINE _GL_EXTERN_INLINE +#include #include "execinfo.h" diff --git a/lib/fcntl.c b/lib/fcntl.c index abdd7b89890..15220c554f0 100644 --- a/lib/fcntl.c +++ b/lib/fcntl.c @@ -56,19 +56,15 @@ dupfd (int oldfd, int newfd, int flags) { /* Mingw has no way to create an arbitrary fd. Iterate until all file descriptors less than newfd are filled up. */ - HANDLE curr_process = GetCurrentProcess (); - HANDLE old_handle = (HANDLE) _get_osfhandle (oldfd); - unsigned char fds_to_close[OPEN_MAX_MAX / CHAR_BIT]; - unsigned int fds_to_close_bound = 0; - int result; - BOOL inherit = flags & O_CLOEXEC ? FALSE : TRUE; - int mode; if (newfd < 0 || getdtablesize () <= newfd) { errno = EINVAL; return -1; } + + HANDLE old_handle = (HANDLE) _get_osfhandle (oldfd); + int mode; if (old_handle == INVALID_HANDLE_VALUE || (mode = _setmode (oldfd, O_BINARY)) == -1) { @@ -80,6 +76,11 @@ dupfd (int oldfd, int newfd, int flags) _setmode (oldfd, mode); flags |= mode; + HANDLE curr_process = GetCurrentProcess (); + BOOL inherit = flags & O_CLOEXEC ? FALSE : TRUE; + unsigned char fds_to_close[OPEN_MAX_MAX / CHAR_BIT]; + unsigned int fds_to_close_bound = 0; + int result; for (;;) { HANDLE new_handle; @@ -205,8 +206,9 @@ fcntl (int fd, int action, /* arg */...) #endif { va_list arg; - int result = -1; va_start (arg, action); + + int result = -1; switch (action) { case F_DUPFD: @@ -432,7 +434,9 @@ fcntl (int fd, int action, /* arg */...) break; } } + va_end (arg); + return result; } @@ -542,10 +546,7 @@ rpl_fcntl_DUPFD_CLOEXEC (int fd, int target) static int klibc_dupdirfd (int fd, int minfd) { - int tempfd; - int dupfd; - - tempfd = open ("NUL", O_RDONLY); + int tempfd = open ("NUL", O_RDONLY); if (tempfd == -1) return -1; @@ -557,7 +558,7 @@ klibc_dupdirfd (int fd, int minfd) if (__libc_Back_ioFHToPath (fd, path, sizeof (path))) return -1; - dupfd = open (path, O_RDONLY); + int dupfd = open (path, O_RDONLY); if (dupfd == -1) return -1; @@ -568,7 +569,7 @@ klibc_dupdirfd (int fd, int minfd) tempfd = dupfd; } - dupfd = klibc_dupdirfd (fd, minfd); + int dupfd = klibc_dupdirfd (fd, minfd); close (tempfd); @@ -579,77 +580,78 @@ static int klibc_fcntl (int fd, int action, /* arg */...) { va_list arg_ptr; - int arg; - struct stat sbuf; - int result; - va_start (arg_ptr, action); - arg = va_arg (arg_ptr, int); - result = fcntl (fd, action, arg); + + int arg = va_arg (arg_ptr, int); + int result = fcntl (fd, action, arg); /* EPERM for F_DUPFD, ENOTSUP for others */ - if (result == -1 && (errno == EPERM || errno == ENOTSUP) - && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode)) + if (result == -1 && (errno == EPERM || errno == ENOTSUP)) { - PLIBCFH pFH; - unsigned fFlags; - - switch (action) + struct stat sbuf; + if (!fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode)) { - case F_DUPFD: - result = klibc_dupdirfd (fd, arg); - break; - - case F_GETFD: - pFH = __libc_FH (fd); - if (!pFH) + switch (action) { - errno = EBADF; + case F_DUPFD: + result = klibc_dupdirfd (fd, arg); break; - } - - result = (pFH->fFlags & ((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT ) - | O_NOINHERIT)) ? FD_CLOEXEC : 0; - break; - case F_SETFD: - if (arg & ~FD_CLOEXEC) - break; - - pFH = __libc_FH (fd); - if (!pFH) - { - errno = EBADF; + case F_GETFD: + { + PLIBCFH pFH = __libc_FH (fd); + if (!pFH) + { + errno = EBADF; + break; + } + + result = (pFH->fFlags & ((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT ) + | O_NOINHERIT)) ? FD_CLOEXEC : 0; + } break; - } - - fFlags = pFH->fFlags; - if (arg & FD_CLOEXEC) - fFlags |= (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT; - else - fFlags &= ~((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT); - result = __libc_FHSetFlags (pFH, fd, fFlags); - if (result < 0) - { - errno = -result; - result = -1; - } - break; + case F_SETFD: + { + if (arg & ~FD_CLOEXEC) + break; + + PLIBCFH pFH = __libc_FH (fd); + if (!pFH) + { + errno = EBADF; + break; + } + + unsigned fFlags = pFH->fFlags; + if (arg & FD_CLOEXEC) + fFlags |= (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT; + else + fFlags &= ~((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT); + + result = __libc_FHSetFlags (pFH, fd, fFlags); + if (result < 0) + { + errno = -result; + result = -1; + } + } + break; - case F_GETFL: - result = 0; - break; + case F_GETFL: + result = 0; + break; - case F_SETFL: - if (arg != 0) - break; + case F_SETFL: + if (arg != 0) + break; - result = 0; - break; + result = 0; + break; - default: - errno = EINVAL; - break; + default: + errno = EINVAL; + break; + } } } diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c index 9a5a18aabcf..d5a52b5b2f8 100644 --- a/lib/file-has-acl.c +++ b/lib/file-has-acl.c @@ -161,7 +161,6 @@ aclinfo_has_xattr (struct aclinfo const *ai, char const *xattr) static void get_aclinfo (int fd, char const *name, struct aclinfo *ai, int flags) { - int scontext_err = ENOTSUP; ai->buf = ai->u.__gl_acl_ch; ssize_t acl_alloc = sizeof ai->u.__gl_acl_ch; @@ -221,6 +220,7 @@ get_aclinfo (int fd, char const *name, struct aclinfo *ai, int flags) } /* A security context can exist only if extended attributes do. */ + int scontext_err = ENOTSUP; if (flags & ACL_GET_SCONTEXT && (0 < ai->size || aclinfo_may_indicate_xattr (ai))) { @@ -781,11 +781,9 @@ fdfile_has_aclinfo (MAYBE_UNUSED int fd, { struct acl_entry entries[NACLENTRIES]; - int count; - - count = (fd < 0 - ? getacl (name, NACLENTRIES, entries) - : fgetacl (fd, NACLENTRIES, entries)); + int count = (fd < 0 + ? getacl (name, NACLENTRIES, entries) + : fgetacl (fd, NACLENTRIES, entries)); if (count < 0) { @@ -827,10 +825,9 @@ fdfile_has_aclinfo (MAYBE_UNUSED int fd, { struct acl entries[NACLVENTRIES]; - int count; /* Ignore FD, unfortunately. */ - count = acl ((char *) name, ACL_GET, NACLVENTRIES, entries); + int count = acl ((char *) name, ACL_GET, NACLVENTRIES, entries); if (count < 0) { @@ -867,13 +864,13 @@ fdfile_has_aclinfo (MAYBE_UNUSED int fd, char aclbuf[1024]; void *acl = aclbuf; size_t aclsize = sizeof (aclbuf); - mode_t mode; for (;;) { /* The docs say that type being 0 is equivalent to ACL_ANY, but it is not true, in AIX 5.3. */ type.u64 = ACL_ANY; + mode_t mode; if (0 <= (fd < 0 ? aclx_get (name, 0, &type, aclbuf, &aclsize, &mode) : aclx_fget (fd, 0, &type, aclbuf, &aclsize, &mode))) @@ -934,10 +931,9 @@ fdfile_has_aclinfo (MAYBE_UNUSED int fd, { struct acl entries[NACLENTRIES]; - int count; /* Ignore FD, unfortunately. */ - count = acl ((char *) name, ACL_GET, NACLENTRIES, entries); + int count = acl ((char *) name, ACL_GET, NACLENTRIES, entries); if (count < 0) { diff --git a/lib/fseterr.c b/lib/fseterr.c index 40aca95c8eb..e84516f4236 100644 --- a/lib/fseterr.c +++ b/lib/fseterr.c @@ -59,14 +59,10 @@ fseterr (FILE *fp) Not activated on any system, because there is no way to repair FP when the sequence of system calls fails, and library code should not call abort(). */ - int saved_errno; - int fd; - int fd2; - - saved_errno = errno; + int saved_errno = errno; fflush (fp); - fd = fileno (fp); - fd2 = dup (fd); + int fd = fileno (fp); + int fd2 = dup (fd); if (fd2 >= 0) { close (fd); diff --git a/lib/fstatat.c b/lib/fstatat.c index 6029de78842..d72c09932fd 100644 --- a/lib/fstatat.c +++ b/lib/fstatat.c @@ -71,11 +71,10 @@ int rpl_fstatat (int fd, char const *file, struct stat *st, int flag) { int result = normal_fstatat (fd, file, st, flag); - size_t len; - if (LSTAT_FOLLOWS_SLASHED_SYMLINK || result != 0) return result; - len = strlen (file); + + size_t len = strlen (file); if (flag & AT_SYMLINK_NOFOLLOW) { /* Fix lstat behavior. */ diff --git a/lib/fsusage.c b/lib/fsusage.c index 64a12c5d48e..bd23b443dc0 100644 --- a/lib/fsusage.c +++ b/lib/fsusage.c @@ -91,10 +91,12 @@ static int statvfs_works (void) { static int statvfs_works_cache = -1; - struct utsname name; if (statvfs_works_cache < 0) - statvfs_works_cache = (uname (&name) == 0 - && 0 <= strverscmp (name.release, "2.6.36")); + { + struct utsname name; + statvfs_works_cache = (uname (&name) == 0 + && 0 <= strverscmp (name.release, "2.6.36")); + } return statvfs_works_cache; } # endif diff --git a/lib/fsync.c b/lib/fsync.c index dcb2d637745..5b7183c8737 100644 --- a/lib/fsync.c +++ b/lib/fsync.c @@ -44,7 +44,6 @@ int fsync (int fd) { HANDLE h = (HANDLE) _get_osfhandle (fd); - DWORD err; if (h == INVALID_HANDLE_VALUE) { @@ -58,7 +57,7 @@ fsync (int fd) * errors. MSDN is useless as usual - in this case it doesn't * document the full range of errors. */ - err = GetLastError (); + DWORD err = GetLastError (); switch (err) { case ERROR_ACCESS_DENIED: diff --git a/lib/getdelim.c b/lib/getdelim.c index 4cd5eca1895..4b4a0c9b1a6 100644 --- a/lib/getdelim.c +++ b/lib/getdelim.c @@ -62,9 +62,6 @@ alloc_failed (void) ssize_t getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) { - ssize_t result; - size_t cur_len = 0; - if (lineptr == NULL || n == NULL /* glibc already declares this function as __nonnull ((4)). Avoid a gcc warning "‘nonnull’ argument ‘fp’ compared to NULL". */ @@ -79,6 +76,8 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) flockfile (fp); + ssize_t result; + if (*lineptr == NULL || *n == 0) { char *new_lineptr; @@ -93,6 +92,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) *lineptr = new_lineptr; } + size_t cur_len = 0; for (;;) { int i; @@ -110,7 +110,6 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) size_t needed_max = SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX; size_t needed = 2 * *n + 1; /* Be generous. */ - char *new_lineptr; if (needed_max < needed) needed = needed_max; @@ -121,7 +120,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp) goto unlock_return; } - new_lineptr = (char *) realloc (*lineptr, needed); + char *new_lineptr = (char *) realloc (*lineptr, needed); if (new_lineptr == NULL) { alloc_failed (); diff --git a/lib/getgroups.c b/lib/getgroups.c index 402206bf886..d788601db75 100644 --- a/lib/getgroups.c +++ b/lib/getgroups.c @@ -68,9 +68,6 @@ int posix_getgroups (int, gid_t []) __asm ("_getgroups"); int rpl_getgroups (int n, gid_t *group) { - int n_groups; - GETGROUPS_T *gbuf; - if (n < 0) { errno = EINVAL; @@ -79,19 +76,18 @@ rpl_getgroups (int n, gid_t *group) if (n != 0 || !GETGROUPS_ZERO_BUG) { - int result; - if (sizeof *group == sizeof *gbuf) + if (sizeof *group == sizeof (GETGROUPS_T)) return getgroups (n, (GETGROUPS_T *) group); - if (SIZE_MAX / sizeof *gbuf <= n) + if (SIZE_MAX / sizeof (GETGROUPS_T) <= n) { errno = ENOMEM; return -1; } - gbuf = malloc (n * sizeof *gbuf); + GETGROUPS_T *gbuf = malloc (n * sizeof *gbuf); if (!gbuf) return -1; - result = getgroups (n, gbuf); + int result = getgroups (n, gbuf); if (0 <= result) { n = result; @@ -108,18 +104,18 @@ rpl_getgroups (int n, gid_t *group) /* No need to worry about address arithmetic overflow here, since the ancient systems that we're running on have low limits on the number of secondary groups. */ - gbuf = malloc (n * sizeof *gbuf); + GETGROUPS_T *gbuf = malloc (n * sizeof *gbuf); if (!gbuf) return -1; - n_groups = getgroups (n, gbuf); + int n_groups = getgroups (n, gbuf); if (n_groups == -1 ? errno != EINVAL : n_groups < n) - break; + { + free (gbuf); + return n_groups; + } free (gbuf); n *= 2; } - - free (gbuf); - return n_groups; } #endif /* HAVE_GETGROUPS */ diff --git a/lib/getloadavg.c b/lib/getloadavg.c index ec7305f5d48..cf7e0154da5 100644 --- a/lib/getloadavg.c +++ b/lib/getloadavg.c @@ -384,51 +384,47 @@ getloadavg (double loadavg[], int nelem) # if !defined (LDAV_DONE) && defined (HAVE_LIBKSTAT) /* Solaris <= 2.6 */ /* Use libkstat because we don't have to be root. */ # define LDAV_DONE - kstat_ctl_t *kc; - kstat_t *ksp; - kstat_named_t *kn; - int saved_errno; - - kc = kstat_open (); - if (kc == NULL) - return -1; - ksp = kstat_lookup (kc, "unix", 0, "system_misc"); - if (ksp == NULL) - return -1; - if (kstat_read (kc, ksp, 0) == -1) - return -1; - - - kn = kstat_data_lookup (ksp, "avenrun_1min"); - if (kn == NULL) - { - /* Return -1 if no load average information is available. */ - nelem = 0; - elem = -1; - } - - if (nelem >= 1) - loadavg[elem++] = (double) kn->value.ul / FSCALE; - - if (nelem >= 2) - { - kn = kstat_data_lookup (ksp, "avenrun_5min"); - if (kn != NULL) - { - loadavg[elem++] = (double) kn->value.ul / FSCALE; + { + kstat_ctl_t *kc = kstat_open (); + if (kc == NULL) + return -1; + kstat_t *ksp = kstat_lookup (kc, "unix", 0, "system_misc"); + if (ksp == NULL) + return -1; + if (kstat_read (kc, ksp, 0) == -1) + return -1; - if (nelem >= 3) - { - kn = kstat_data_lookup (ksp, "avenrun_15min"); - if (kn != NULL) - loadavg[elem++] = (double) kn->value.ul / FSCALE; - } - } - } + kstat_named_t *kn = kstat_data_lookup (ksp, "avenrun_1min"); + if (kn == NULL) + { + /* Return -1 if no load average information is available. */ + nelem = 0; + elem = -1; + } + + if (nelem >= 1) + loadavg[elem++] = (double) kn->value.ul / FSCALE; + + if (nelem >= 2) + { + kn = kstat_data_lookup (ksp, "avenrun_5min"); + if (kn != NULL) + { + loadavg[elem++] = (double) kn->value.ul / FSCALE; + + if (nelem >= 3) + { + kn = kstat_data_lookup (ksp, "avenrun_15min"); + if (kn != NULL) + loadavg[elem++] = (double) kn->value.ul / FSCALE; + } + } + } - saved_errno = errno; - kstat_close (kc); - errno = saved_errno; + int saved_errno = errno; + kstat_close (kc); + errno = saved_errno; + } # endif /* HAVE_LIBKSTAT */ # if !defined (LDAV_DONE) && defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC) @@ -489,13 +485,12 @@ getloadavg (double loadavg[], int nelem) char ldavgbuf[3 * (INT_STRLEN_BOUND (int) + sizeof ".00 ")]; char const *ptr = ldavgbuf; - int fd, count, saved_errno; - fd = open ("/proc/loadavg", O_RDONLY | O_CLOEXEC); + int fd = open ("/proc/loadavg", O_RDONLY | O_CLOEXEC); if (fd == -1) return -1; - count = read (fd, ldavgbuf, sizeof ldavgbuf - 1); - saved_errno = errno; + int count = read (fd, ldavgbuf, sizeof ldavgbuf - 1); + int saved_errno = errno; (void) close (fd); errno = saved_errno; if (count <= 0) @@ -504,9 +499,6 @@ getloadavg (double loadavg[], int nelem) for (elem = 0; elem < nelem; elem++) { - double numerator = 0; - double denominator = 1; - while (*ptr == ' ') ptr++; @@ -522,6 +514,9 @@ getloadavg (double loadavg[], int nelem) break; } + double numerator = 0; + double denominator = 1; + while ('0' <= *ptr && *ptr <= '9') numerator = 10 * numerator + (*ptr++ - '0'); @@ -544,12 +539,11 @@ getloadavg (double loadavg[], int nelem) # define NETBSD_LDAV_FILE "/kern/loadavg" # endif - unsigned long int load_ave[3], scale; - int count; - char readbuf[4 * INT_BUFSIZE_BOUND (unsigned long int) + 1]; int fd = open (NETBSD_LDAV_FILE, O_RDONLY | O_CLOEXEC); if (fd < 0) return fd; + + char readbuf[4 * INT_BUFSIZE_BOUND (unsigned long int) + 1]; int nread = read (fd, readbuf, sizeof readbuf - 1); int saved_errno = errno; close (fd); @@ -559,9 +553,11 @@ getloadavg (double loadavg[], int nelem) return -1; } readbuf[nread] = '\0'; - count = sscanf (readbuf, "%lu %lu %lu %lu\n", - &load_ave[0], &load_ave[1], &load_ave[2], - &scale); + + unsigned long int load_ave[3], scale; + int count = sscanf (readbuf, "%lu %lu %lu %lu\n", + &load_ave[0], &load_ave[1], &load_ave[2], + &scale); if (count != 4) { errno = ENOTSUP; @@ -579,10 +575,6 @@ getloadavg (double loadavg[], int nelem) # define LDAV_DONE /* The NeXT code was adapted from iscreen 3.2. */ - host_t host; - struct processor_set_basic_info info; - unsigned int info_count; - /* We only know how to get the 1-minute average for this system, so even if the caller asks for more than 1, we only return 1. */ @@ -594,7 +586,9 @@ getloadavg (double loadavg[], int nelem) if (getloadavg_initialized) { - info_count = PROCESSOR_SET_BASIC_INFO_COUNT; + host_t host; + struct processor_set_basic_info info; + unsigned int info_count = PROCESSOR_SET_BASIC_INFO_COUNT; if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, (processor_set_info_t) &info, &info_count) != KERN_SUCCESS) @@ -620,11 +614,6 @@ getloadavg (double loadavg[], int nelem) can be gathered with inq_stats system calls. We only know how to get the 1-minute average for this system. */ - struct proc_summary proc_sum_data; - struct stat_descr proc_info; - double load; - register unsigned int j; - if (cpus == 0) { register unsigned int c; @@ -660,6 +649,9 @@ getloadavg (double loadavg[], int nelem) samples = cpus < 2 ? 3 : (2 * cpus / 3); } + struct proc_summary proc_sum_data; + + struct stat_descr proc_info; proc_info.sd_next = 0; proc_info.sd_subsys = SUBSYS_PROC; proc_info.sd_type = PROCTYPE_SUMMARY; @@ -670,8 +662,8 @@ getloadavg (double loadavg[], int nelem) if (inq_stats (1, &proc_info) != 0) return -1; - load = proc_sum_data.ps_nrunnable; - j = 0; + double load = proc_sum_data.ps_nrunnable; + register unsigned int j = 0; for (unsigned int i = samples - 1; i > 0; --i) { load += proc_sum_data.ps_nrun[j]; @@ -797,8 +789,6 @@ getloadavg (double loadavg[], int nelem) # define LDAV_PRIVILEGED /* This code requires special installation. */ - LOAD_AVE_TYPE load_ave[3]; - /* Get the address of LDAV_SYMBOL. */ if (offset == 0) { @@ -857,6 +847,8 @@ getloadavg (double loadavg[], int nelem) # endif /* SUNOS_5 */ } + LOAD_AVE_TYPE load_ave[3]; + /* If we can, get the load average values. */ if (offset && getloadavg_initialized) { diff --git a/lib/getopt.c b/lib/getopt.c index d61bf8619c0..4f2c32f41ec 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -133,7 +133,6 @@ exchange (char **argv, struct _getopt_data *d) int bottom = d->__first_nonopt; int middle = d->__last_nonopt; int top = d->optind; - char *tem; /* Exchange the shorter segment with the far end of the longer segment. That puts the shorter segment into the right place. @@ -151,7 +150,7 @@ exchange (char **argv, struct _getopt_data *d) /* Swap it with the top part of the top segment. */ for (i = 0; i < len; i++) { - tem = argv[bottom + i]; + char *tem = argv[bottom + i]; argv[bottom + i] = argv[top - (middle - bottom) + i]; argv[top - (middle - bottom) + i] = tem; } @@ -167,7 +166,7 @@ exchange (char **argv, struct _getopt_data *d) /* Swap it with the bottom part of the bottom segment. */ for (i = 0; i < len; i++) { - tem = argv[bottom + i]; + char *tem = argv[bottom + i]; argv[bottom + i] = argv[middle + i]; argv[middle + i] = tem; } @@ -196,28 +195,29 @@ process_long_option (int argc, char **argv, const char *optstring, int long_only, struct _getopt_data *d, int print_errors, const char *prefix) { - char *nameend; - size_t namelen; - const struct option *p; - const struct option *pfound = NULL; - int n_options; - int option_index; + char *nameend; for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; - namelen = nameend - d->__nextchar; + size_t namelen = nameend - d->__nextchar; /* First look for an exact match, counting the options as a side effect. */ - for (p = longopts, n_options = 0; p->name; p++, n_options++) - if (!strncmp (p->name, d->__nextchar, namelen) - && namelen == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - option_index = n_options; - break; - } + const struct option *pfound = NULL; + int n_options; + int option_index; + { + const struct option *p; + for (p = longopts, n_options = 0; p->name; p++, n_options++) + if (!strncmp (p->name, d->__nextchar, namelen) + && namelen == strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + option_index = n_options; + break; + } + } if (pfound == NULL) { @@ -227,6 +227,7 @@ process_long_option (int argc, char **argv, const char *optstring, unsigned char ambig_fallback; void *ambig_malloced = NULL; int indfound = -1; + const struct option *p; for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp (p->name, d->__nextchar, namelen)) @@ -475,11 +476,11 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, const struct option *longopts, int *longind, int long_only, struct _getopt_data *d, int posixly_correct) { - int print_errors = d->opterr; - if (argc < 1) return -1; + int print_errors = d->opterr; + d->optarg = NULL; if (d->optind == 0 || !d->__initialized) @@ -594,11 +595,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, if (long_only && (argv[d->optind][2] || !strchr (optstring, argv[d->optind][1]))) { - int code; d->__nextchar = argv[d->optind] + 1; - code = process_long_option (argc, argv, optstring, longopts, - longind, long_only, d, - print_errors, "-"); + int code = process_long_option (argc, argv, optstring, longopts, + longind, long_only, d, + print_errors, "-"); if (code != -1) return code; } @@ -707,14 +707,12 @@ _getopt_internal (int argc, char **argv, const char *optstring, const struct option *longopts, int *longind, int long_only, int posixly_correct) { - int result; - getopt_data.optind = optind; getopt_data.opterr = opterr; - result = _getopt_internal_r (argc, argv, optstring, longopts, - longind, long_only, &getopt_data, - posixly_correct); + int result = _getopt_internal_r (argc, argv, optstring, longopts, + longind, long_only, &getopt_data, + posixly_correct); optind = getopt_data.optind; optarg = getopt_data.optarg; @@ -751,14 +749,13 @@ GETOPT_ENTRY(getopt, 1) int main (int argc, char **argv) { - int c; int digit_optind = 0; while (1) { int this_option_optind = optind ? optind : 1; - c = getopt (argc, argv, "abc:d:0123456789"); + int c = getopt (argc, argv, "abc:d:0123456789"); if (c == -1) break; diff --git a/lib/getopt1.c b/lib/getopt1.c index c8566845b7d..e6781753b86 100644 --- a/lib/getopt1.c +++ b/lib/getopt1.c @@ -73,7 +73,6 @@ _getopt_long_only_r (int argc, char **argv, const char *options, int main (int argc, char **argv) { - int c; int digit_optind = 0; while (1) @@ -91,8 +90,8 @@ main (int argc, char **argv) {0, 0, 0, 0} }; - c = getopt_long (argc, argv, "abc:d:0123456789", - long_options, &option_index); + int c = getopt_long (argc, argv, "abc:d:0123456789", + long_options, &option_index); if (c == -1) break; diff --git a/lib/gettext.h b/lib/gettext.h index 0650abc9a3d..68f56f91962 100644 --- a/lib/gettext.h +++ b/lib/gettext.h @@ -298,12 +298,11 @@ dcpgettext_expr (const char *domain, if (msg_ctxt_id != NULL) #endif { - int found_translation; memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); msg_ctxt_id[msgctxt_len - 1] = '\004'; memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); translation = dcgettext (domain, msg_ctxt_id, category); - found_translation = (translation != msg_ctxt_id); + int found_translation = (translation != msg_ctxt_id); #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS if (msg_ctxt_id != buf) free (msg_ctxt_id); @@ -346,12 +345,11 @@ dcnpgettext_expr (const char *domain, if (msg_ctxt_id != NULL) #endif { - int found_translation; memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); msg_ctxt_id[msgctxt_len - 1] = '\004'; memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); - found_translation = !(translation == msg_ctxt_id || translation == msgid_plural); + int found_translation = !(translation == msg_ctxt_id || translation == msgid_plural); #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS if (msg_ctxt_id != buf) free (msg_ctxt_id); diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c index 304e23b23c7..7e239a57232 100644 --- a/lib/gettimeofday.c +++ b/lib/gettimeofday.c @@ -92,12 +92,12 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz) microseconds. More discussion on this topic: . */ - FILETIME current_time; - # if !(_WIN32_WINNT >= _WIN32_WINNT_WIN8) if (!initialized) initialize (); # endif + + FILETIME current_time; if (GetSystemTimePreciseAsFileTimeFunc != NULL) GetSystemTimePreciseAsFileTimeFunc (¤t_time); else diff --git a/lib/group-member.c b/lib/group-member.c index 34938a1b05e..13692636464 100644 --- a/lib/group-member.c +++ b/lib/group-member.c @@ -73,12 +73,11 @@ get_group_info (struct group_info *gi) int group_member (gid_t gid) { - int found; struct group_info gi; int n_groups = get_group_info (&gi); /* Search through the list looking for GID. */ - found = 0; + int found = 0; for (int i = 0; i < n_groups; i++) { if (gid == gi.group[i]) @@ -100,9 +99,7 @@ main (int argc, char **argv) { for (int i = 1; i < argc; i++) { - gid_t gid; - - gid = atoi (argv[i]); + gid_t gid = atoi (argv[i]); printf ("%d: %s\n", gid, group_member (gid) ? "yes" : "no"); } exit (0); diff --git a/lib/issymlink.c b/lib/issymlink.c index dbf56c037c4..85bd0715406 100644 --- a/lib/issymlink.c +++ b/lib/issymlink.c @@ -14,7 +14,6 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define _GL_ISSYMLINK_INLINE _GL_EXTERN_INLINE +#include #include "issymlink.h" diff --git a/lib/issymlinkat.c b/lib/issymlinkat.c index ebd937e91bc..b98f38e8412 100644 --- a/lib/issymlinkat.c +++ b/lib/issymlinkat.c @@ -14,7 +14,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include - #define _GL_ISSYMLINKAT_INLINE _GL_EXTERN_INLINE +#include #include "issymlinkat.h" diff --git a/lib/md5-stream.c b/lib/md5-stream.c index a5d6a3109a4..76d7c414664 100644 --- a/lib/md5-stream.c +++ b/lib/md5-stream.c @@ -69,15 +69,14 @@ md5_stream (FILE *stream, void *resblock) struct md5_ctx ctx; md5_init_ctx (&ctx); - size_t sum; /* Iterate over full file contents. */ + size_t sum; while (1) { /* We read the file in blocks of BLOCKSIZE bytes. One call of the computation function processes the whole buffer so that with the next round of the loop another block can be read. */ - size_t n; sum = 0; /* Read block. Take care for partial reads. */ @@ -91,7 +90,7 @@ md5_stream (FILE *stream, void *resblock) if (feof (stream)) goto process_partial_block; - n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); + size_t n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); sum += n; diff --git a/lib/memrchr.c b/lib/memrchr.c index 0c4022caff1..0321cb3b0de 100644 --- a/lib/memrchr.c +++ b/lib/memrchr.c @@ -52,103 +52,104 @@ __memrchr (void const *s, int c_in, size_t n) performance. */ typedef unsigned long int longword; - const unsigned char *char_ptr; - const longword *longword_ptr; - longword repeated_one; - longword repeated_c; - unsigned reg_char c; + unsigned reg_char c = (unsigned char) c_in; - c = (unsigned char) c_in; + const longword *longword_ptr; /* Handle the last few bytes by reading one byte at a time. Do this until CHAR_PTR is aligned on a longword boundary. */ - for (char_ptr = (const unsigned char *) s + n; - n > 0 && (size_t) char_ptr % sizeof (longword) != 0; - --n) - if (*--char_ptr == c) - return (void *) char_ptr; + { + const unsigned char *char_ptr; + for (char_ptr = (const unsigned char *) s + n; + n > 0 && (size_t) char_ptr % sizeof (longword) != 0; + --n) + if (*--char_ptr == c) + return (void *) char_ptr; - longword_ptr = (const void *) char_ptr; + longword_ptr = (const void *) char_ptr; + } /* All these elucidatory comments refer to 4-byte longwords, but the theory applies equally well to any size longwords. */ - - /* Compute auxiliary longword values: - repeated_one is a value which has a 1 in every byte. - repeated_c has c in every byte. */ - repeated_one = 0x01010101; - repeated_c = c | (c << 8); - repeated_c |= repeated_c << 16; - if (0xffffffffU < (longword) -1) - { - repeated_one |= repeated_one << 31 << 1; - repeated_c |= repeated_c << 31 << 1; - if (8 < sizeof (longword)) - for (size_t i = 64; i < sizeof (longword) * 8; i *= 2) - { - repeated_one |= repeated_one << i; - repeated_c |= repeated_c << i; - } - } - - /* Instead of the traditional loop which tests each byte, we will test a - longword at a time. The tricky part is testing if *any of the four* - bytes in the longword in question are equal to c. We first use an xor - with repeated_c. This reduces the task to testing whether *any of the - four* bytes in longword1 is zero. - - We compute tmp = - ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7). - That is, we perform the following operations: - 1. Subtract repeated_one. - 2. & ~longword1. - 3. & a mask consisting of 0x80 in every byte. - Consider what happens in each byte: - - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, - and step 3 transforms it into 0x80. A carry can also be propagated - to more significant bytes. - - If a byte of longword1 is nonzero, let its lowest 1 bit be at - position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, - the byte ends in a single bit of value 0 and k bits of value 1. - After step 2, the result is just k bits of value 1: 2^k - 1. After - step 3, the result is 0. And no carry is produced. - So, if longword1 has only non-zero bytes, tmp is zero. - Whereas if longword1 has a zero byte, call j the position of the least - significant zero byte. Then the result has a zero at positions 0, ..., - j-1 and a 0x80 at position j. We cannot predict the result at the more - significant bytes (positions j+1..3), but it does not matter since we - already have a non-zero bit at position 8*j+7. + { + /* Compute auxiliary longword values: + repeated_one is a value which has a 1 in every byte. + repeated_c has c in every byte. */ + longword repeated_one = 0x01010101; + longword repeated_c = c | (c << 8); + repeated_c |= repeated_c << 16; + if (0xffffffffU < (longword) -1) + { + repeated_one |= repeated_one << 31 << 1; + repeated_c |= repeated_c << 31 << 1; + if (8 < sizeof (longword)) + for (size_t i = 64; i < sizeof (longword) * 8; i *= 2) + { + repeated_one |= repeated_one << i; + repeated_c |= repeated_c << i; + } + } + + /* Instead of the traditional loop which tests each byte, we will test a + longword at a time. The tricky part is testing if *any of the four* + bytes in the longword in question are equal to c. We first use an xor + with repeated_c. This reduces the task to testing whether *any of the + four* bytes in longword1 is zero. + + We compute tmp = + ((longword1 - repeated_one) & ~longword1) & (repeated_one << 7). + That is, we perform the following operations: + 1. Subtract repeated_one. + 2. & ~longword1. + 3. & a mask consisting of 0x80 in every byte. + Consider what happens in each byte: + - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, + and step 3 transforms it into 0x80. A carry can also be propagated + to more significant bytes. + - If a byte of longword1 is nonzero, let its lowest 1 bit be at + position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, + the byte ends in a single bit of value 0 and k bits of value 1. + After step 2, the result is just k bits of value 1: 2^k - 1. After + step 3, the result is 0. And no carry is produced. + So, if longword1 has only non-zero bytes, tmp is zero. + Whereas if longword1 has a zero byte, call j the position of the least + significant zero byte. Then the result has a zero at positions 0, ..., + j-1 and a 0x80 at position j. We cannot predict the result at the more + significant bytes (positions j+1..3), but it does not matter since we + already have a non-zero bit at position 8*j+7. So, the test whether any byte in longword1 is zero is equivalent to testing whether tmp is nonzero. */ - while (n >= sizeof (longword)) - { - longword longword1 = *--longword_ptr ^ repeated_c; - - if ((((longword1 - repeated_one) & ~longword1) - & (repeated_one << 7)) != 0) - { - longword_ptr++; - break; - } - n -= sizeof (longword); - } - - char_ptr = (const unsigned char *) longword_ptr; - - /* At this point, we know that either n < sizeof (longword), or one of the - sizeof (longword) bytes starting at char_ptr is == c. On little-endian - machines, we could determine the first such byte without any further - memory accesses, just by looking at the tmp result from the last loop - iteration. But this does not work on big-endian machines. Choose code - that works in both cases. */ - - while (n-- > 0) - { - if (*--char_ptr == c) - return (void *) char_ptr; - } + while (n >= sizeof (longword)) + { + longword longword1 = *--longword_ptr ^ repeated_c; + + if ((((longword1 - repeated_one) & ~longword1) + & (repeated_one << 7)) != 0) + { + longword_ptr++; + break; + } + n -= sizeof (longword); + } + } + + { + const unsigned char *char_ptr = (const unsigned char *) longword_ptr; + + /* At this point, we know that either n < sizeof (longword), or one of the + sizeof (longword) bytes starting at char_ptr is == c. On little-endian + machines, we could determine the first such byte without any further + memory accesses, just by looking at the tmp result from the last loop + iteration. But this does not work on big-endian machines. Choose code + that works in both cases. */ + while (n-- > 0) + { + if (*--char_ptr == c) + return (void *) char_ptr; + } + } return NULL; } diff --git a/lib/nanosleep.c b/lib/nanosleep.c index cfafa4e37e1..904680c76f5 100644 --- a/lib/nanosleep.c +++ b/lib/nanosleep.c @@ -64,9 +64,8 @@ nanosleep (const struct timespec *requested_delay, while (limit < seconds) { - int result; intermediate.tv_sec = limit; - result = nanosleep (&intermediate, remaining_delay); + int result = nanosleep (&intermediate, remaining_delay); seconds -= limit; if (result) { diff --git a/lib/nproc.c b/lib/nproc.c index 1cccfc56065..75adbbdc42e 100644 --- a/lib/nproc.c +++ b/lib/nproc.c @@ -100,9 +100,7 @@ num_processors_via_affinity_mask (void) } #elif HAVE_PTHREAD_GETAFFINITY_NP && defined __NetBSD__ && 0 { - cpuset_t *set; - - set = cpuset_create (); + cpuset_t *set = cpuset_create (); if (set != NULL) { unsigned long count = 0; @@ -187,9 +185,7 @@ num_processors_via_affinity_mask (void) } #elif HAVE_SCHED_GETAFFINITY_NP /* NetBSD >= 5 */ { - cpuset_t *set; - - set = cpuset_create (); + cpuset_t *set = cpuset_create (); if (set != NULL) { unsigned long count = 0; @@ -370,18 +366,19 @@ num_processors_available (enum nproc_query query) static char * cgroup2_mount (void) { - FILE *fp; - char *ret = NULL; /* Check the usual location first. */ if (access ("/sys/fs/cgroup/cgroup.controllers", F_OK) == 0) return strdup ("/sys/fs/cgroup"); + char *ret = NULL; + #if HAVE_SETMNTENT /* Otherwise look for the mount point. */ - struct mntent *mnt; - if (! (fp = setmntent ("/proc/mounts", "r"))) + FILE *fp = setmntent ("/proc/mounts", "r"); + if (! fp) return NULL; + struct mntent *mnt; while ((mnt = getmntent (fp)) != NULL) { if (streq (mnt->mnt_type, "cgroup2")) @@ -403,9 +400,8 @@ static unsigned long int get_cgroup2_cpu_quota (void) { unsigned long int cpu_quota = ULONG_MAX; - FILE *fp; - fp = fopen ("/proc/self/cgroup", "r"); + FILE *fp = fopen ("/proc/self/cgroup", "r"); if (! fp) return cpu_quota; @@ -518,10 +514,8 @@ cpu_quota (void) static unsigned long int parse_omp_threads (char const* threads) { - unsigned long int ret = 0; - if (threads == NULL) - return ret; + return 0; /* The OpenMP spec says that the value assigned to the environment variables "may have leading and trailing white space". */ @@ -543,7 +537,7 @@ parse_omp_threads (char const* threads) return value; } - return ret; + return 0; } unsigned long int @@ -555,9 +549,11 @@ num_processors (enum nproc_query query) programs that are based on OpenMP. */ if (query == NPROC_CURRENT_OVERRIDABLE) { - unsigned long int omp_env_threads, omp_env_limit; - omp_env_threads = parse_omp_threads (getenv ("OMP_NUM_THREADS")); - omp_env_limit = parse_omp_threads (getenv ("OMP_THREAD_LIMIT")); + unsigned long int omp_env_threads = + parse_omp_threads (getenv ("OMP_NUM_THREADS")); + + unsigned long int omp_env_limit = + parse_omp_threads (getenv ("OMP_THREAD_LIMIT")); if (! omp_env_limit) omp_env_limit = ULONG_MAX; diff --git a/lib/openat-proc.c b/lib/openat-proc.c index a333a3f8785..39854c12384 100644 --- a/lib/openat-proc.c +++ b/lib/openat-proc.c @@ -46,9 +46,6 @@ char * openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) { - char *result = buf; - int dirlen; - /* Make sure the caller gets ENOENT when appropriate. */ if (!*file) { @@ -56,6 +53,9 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) return buf; } + char *result = buf; + int dirlen; + #if !(defined __KLIBC__ || defined __MVS__) /* Generic code for Linux, Solaris, and similar platforms. */ # define PROC_SELF_FD_FORMAT "/proc/self/fd/%d/" diff --git a/lib/pselect.c b/lib/pselect.c index f6599f5f23b..9af489b96d8 100644 --- a/lib/pselect.c +++ b/lib/pselect.c @@ -41,16 +41,14 @@ pselect (int nfds, fd_set *restrict rfds, struct timespec const *restrict timeout, sigset_t const *restrict sigmask) { - int select_result; - sigset_t origmask; - struct timeval tv, *tvp; - if (nfds < 0 || nfds > FD_SETSIZE) { errno = EINVAL; return -1; } + struct timeval tv; + struct timeval *tvp; if (timeout) { if (! (0 <= timeout->tv_nsec && timeout->tv_nsec < 1000000000)) @@ -68,12 +66,13 @@ pselect (int nfds, fd_set *restrict rfds, else tvp = NULL; + sigset_t origmask; /* Signal mask munging should be atomic, but this is the best we can do in this emulation. */ if (sigmask) pthread_sigmask (SIG_SETMASK, sigmask, &origmask); - select_result = select (nfds, rfds, wfds, xfds, tvp); + int select_result = select (nfds, rfds, wfds, xfds, tvp); if (sigmask) { diff --git a/lib/pthread_sigmask.c b/lib/pthread_sigmask.c index 0d0a5c211da..a7d78f246f9 100644 --- a/lib/pthread_sigmask.c +++ b/lib/pthread_sigmask.c @@ -31,21 +31,20 @@ pthread_sigmask (int how, const sigset_t *new_mask, sigset_t *old_mask) #undef pthread_sigmask { #if HAVE_PTHREAD_SIGMASK - int ret; - # if PTHREAD_SIGMASK_INEFFECTIVE - sigset_t omask, omask_copy; + sigset_t omask; sigset_t *old_mask_ptr = &omask; sigemptyset (&omask); /* Add a signal unlikely to be blocked, so that OMASK_COPY is unlikely to match the actual mask. */ sigaddset (&omask, SIGILL); + sigset_t omask_copy; memcpy (&omask_copy, &omask, sizeof omask); # else sigset_t *old_mask_ptr = old_mask; # endif - ret = pthread_sigmask (how, new_mask, old_mask_ptr); + int ret = pthread_sigmask (how, new_mask, old_mask_ptr); # if PTHREAD_SIGMASK_INEFFECTIVE if (ret == 0) diff --git a/lib/qcopy-acl.c b/lib/qcopy-acl.c index e86e15544f6..6ec98e8d08c 100644 --- a/lib/qcopy-acl.c +++ b/lib/qcopy-acl.c @@ -114,11 +114,11 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, #else /* no XATTR, so we proceed the old dusty way */ struct permission_context ctx; - - ret = get_permissions (src_name, source_desc, mode, &ctx); - if (ret != 0) + if (get_permissions (src_name, source_desc, mode, &ctx) != 0) return -2; + ret = set_permissions (&ctx, dst_name, dest_desc); + free_permission_context (&ctx); #endif return ret; diff --git a/lib/rawmemchr.c b/lib/rawmemchr.c index afdd7672d29..08ce88c3da6 100644 --- a/lib/rawmemchr.c +++ b/lib/rawmemchr.c @@ -46,89 +46,100 @@ rawmemchr (const void *s, int c_in) /* Verify that the longword type lacks padding bits. */ static_assert (UINTPTR_WIDTH == UCHAR_WIDTH * sizeof (uintptr_t)); - const unsigned char *char_ptr; unsigned char c = c_in; - /* Handle the first few bytes by reading one byte at a time. - Do this until CHAR_PTR is aligned on a natural longword boundary, - as using alignof (longword) might be slower. */ - for (char_ptr = (const unsigned char *) s; - (uintptr_t) char_ptr % sizeof (longword) != 0; - ++char_ptr) - if (*char_ptr == c) - return (void *) char_ptr; - - longword const *longword_ptr = s = char_ptr; - - /* Compute auxiliary longword values: - repeated_one is a value which has a 1 in every byte. - repeated_c has c in every byte. */ - longword repeated_one = (longword) -1 / UCHAR_MAX; - longword repeated_c = repeated_one * c; - longword repeated_hibit = repeated_one * (UCHAR_MAX / 2 + 1); - - /* Instead of the traditional loop which tests each byte, we will - test a longword at a time. The tricky part is testing if any of - the bytes in the longword in question are equal to - c. We first use an xor with repeated_c. This reduces the task - to testing whether any of the bytes in longword1 is zero. - - (The following comments assume 8-bit bytes, as POSIX requires; - the code's use of UCHAR_MAX should work even if bytes have more - than 8 bits.) - - We compute tmp = - ((longword1 - repeated_one) & ~longword1) & (repeated_one * 0x80). - That is, we perform the following operations: - 1. Subtract repeated_one. - 2. & ~longword1. - 3. & a mask consisting of 0x80 in every byte. - Consider what happens in each byte: - - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, - and step 3 transforms it into 0x80. A carry can also be propagated - to more significant bytes. - - If a byte of longword1 is nonzero, let its lowest 1 bit be at - position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, - the byte ends in a single bit of value 0 and k bits of value 1. - After step 2, the result is just k bits of value 1: 2^k - 1. After - step 3, the result is 0. And no carry is produced. - So, if longword1 has only non-zero bytes, tmp is zero. - Whereas if longword1 has a zero byte, call j the position of the least - significant zero byte. Then the result has a zero at positions 0, ..., - j-1 and a 0x80 at position j. We cannot predict the result at the more - significant bytes (positions j+1..3), but it does not matter since we - already have a non-zero bit at position 8*j+7. - - The test whether any byte in longword1 is zero is equivalent - to testing whether tmp is nonzero. - - This test can read beyond the end of a string, depending on where - C_IN is encountered. However, this is considered safe since the - initialization phase ensured that the read will be aligned, - therefore, the read will not cross page boundaries and will not - cause a fault. */ - - while (1) - { - longword longword1 = *longword_ptr ^ repeated_c; - - if ((((longword1 - repeated_one) & ~longword1) & repeated_hibit) != 0) - break; - longword_ptr++; - } - - char_ptr = s = longword_ptr; - - /* At this point, we know that one of the sizeof (longword) bytes - starting at char_ptr is == c. If we knew endianness, we - could determine the first such byte without any further memory - accesses, just by looking at the tmp result from the last loop - iteration. However, the following simple and portable code does - not attempt this potential optimization. */ - - while (*char_ptr != c) - char_ptr++; - return (void *) char_ptr; + { + const unsigned char *char_ptr; + + /* Handle the first few bytes by reading one byte at a time. + Do this until CHAR_PTR is aligned on a natural longword boundary, + as using alignof (longword) might be slower. */ + for (char_ptr = (const unsigned char *) s; + (uintptr_t) char_ptr % sizeof (longword) != 0; + ++char_ptr) + if (*char_ptr == c) + return (void *) char_ptr; + + s = char_ptr; + } + + { + longword const *longword_ptr = s; + + /* Compute auxiliary longword values: + repeated_one is a value which has a 1 in every byte. + repeated_c has c in every byte. */ + longword repeated_one = (longword) -1 / UCHAR_MAX; + longword repeated_c = repeated_one * c; + longword repeated_hibit = repeated_one * (UCHAR_MAX / 2 + 1); + + /* Instead of the traditional loop which tests each byte, we will + test a longword at a time. The tricky part is testing if any of + the bytes in the longword in question are equal to + c. We first use an xor with repeated_c. This reduces the task + to testing whether any of the bytes in longword1 is zero. + + (The following comments assume 8-bit bytes, as POSIX requires; + the code's use of UCHAR_MAX should work even if bytes have more + than 8 bits.) + + We compute tmp = + ((longword1 - repeated_one) & ~longword1) & (repeated_one * 0x80). + That is, we perform the following operations: + 1. Subtract repeated_one. + 2. & ~longword1. + 3. & a mask consisting of 0x80 in every byte. + Consider what happens in each byte: + - If a byte of longword1 is zero, step 1 and 2 transform it into 0xff, + and step 3 transforms it into 0x80. A carry can also be propagated + to more significant bytes. + - If a byte of longword1 is nonzero, let its lowest 1 bit be at + position k (0 <= k <= 7); so the lowest k bits are 0. After step 1, + the byte ends in a single bit of value 0 and k bits of value 1. + After step 2, the result is just k bits of value 1: 2^k - 1. After + step 3, the result is 0. And no carry is produced. + So, if longword1 has only non-zero bytes, tmp is zero. + Whereas if longword1 has a zero byte, call j the position of the least + significant zero byte. Then the result has a zero at positions 0, ..., + j-1 and a 0x80 at position j. We cannot predict the result at the more + significant bytes (positions j+1..3), but it does not matter since we + already have a non-zero bit at position 8*j+7. + + The test whether any byte in longword1 is zero is equivalent + to testing whether tmp is nonzero. + + This test can read beyond the end of a string, depending on where + C_IN is encountered. However, this is considered safe since the + initialization phase ensured that the read will be aligned, + therefore, the read will not cross page boundaries and will not + cause a fault. */ + + while (1) + { + longword longword1 = *longword_ptr ^ repeated_c; + + if ((((longword1 - repeated_one) & ~longword1) & repeated_hibit) != 0) + break; + longword_ptr++; + } + + s = longword_ptr; + } + + { + const unsigned char *char_ptr = s; + + /* At this point, we know that one of the sizeof (longword) bytes + starting at char_ptr is == c. If we knew endianness, we + could determine the first such byte without any further memory + accesses, just by looking at the tmp result from the last loop + iteration. However, the following simple and portable code does + not attempt this potential optimization. */ + + while (*char_ptr != c) + char_ptr++; + return (void *) char_ptr; + } # endif } diff --git a/lib/realloc.c b/lib/realloc.c index cf0bf6e9f70..b0dd28b5da6 100644 --- a/lib/realloc.c +++ b/lib/realloc.c @@ -20,9 +20,9 @@ /* Ensure that we call the system's realloc() below. */ #define _GL_USE_STDLIB_ALLOC 1 -#include #define _GL_REALLOC_INLINE _GL_EXTERN_INLINE +#include #include #include diff --git a/lib/set-permissions.c b/lib/set-permissions.c index 27f41fde514..5f3402cd702 100644 --- a/lib/set-permissions.c +++ b/lib/set-permissions.c @@ -123,7 +123,6 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod) { ace_t entries[6]; int count; - int ret; if (convention) { @@ -217,6 +216,8 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod) entries[4].a_access_mask |= NEW_ACE_EXECUTE; count = 6; } + + int ret; if (desc != -1) ret = facl (desc, ACE_SETACL, count, entries); else @@ -237,7 +238,6 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod) { aclent_t entries[3]; - int ret; entries[0].a_type = USER_OBJ; entries[0].a_id = 0; /* irrelevant */ @@ -249,6 +249,7 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod) entries[2].a_id = 0; entries[2].a_perm = mode & 7; + int ret; if (desc != -1) ret = facl (desc, SETACL, sizeof (entries) / sizeof (aclent_t), entries); @@ -273,8 +274,8 @@ static int context_acl_from_mode (struct permission_context *ctx, const char *name, int desc) { struct stat statbuf; - int ret; + int ret; if (desc != -1) ret = fstat (desc, &statbuf); else @@ -299,8 +300,6 @@ context_acl_from_mode (struct permission_context *ctx, const char *name, int des static int context_aclv_from_mode (struct permission_context *ctx) { - int ret; - ctx->aclv_entries[0].a_type = USER_OBJ; ctx->aclv_entries[0].a_id = 0; /* irrelevant */ ctx->aclv_entries[0].a_perm = (ctx->mode >> 6) & 7; @@ -315,7 +314,7 @@ context_aclv_from_mode (struct permission_context *ctx) ctx->aclv_entries[3].a_perm = ctx->mode & 7; ctx->aclv_count = 4; - ret = aclsort (ctx->aclv_count, 1, ctx->aclv_entries); + int ret = aclsort (ctx->aclv_count, 1, ctx->aclv_entries); if (ret > 0) abort (); return ret; @@ -328,7 +327,6 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod) { acl_type_list_t types; size_t types_size = sizeof (types); - acl_type_t type; if (aclx_gettypes (name, &types, &types_size) < 0 || types.num_entries == 0) @@ -339,11 +337,10 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod) /* XXX Do we need to clear all types of ACLs for the given file, or is it sufficient to clear the first one? */ - type = types.entries[0]; + acl_type_t type = types.entries[0]; if (type.u64 == ACL_AIXC) { union { struct acl a; char room[128]; } u; - int ret; u.a.acl_len = (char *) &u.a.acl_ext[0] - (char *) &u.a; /* no entries */ u.a.acl_mode = mode & ~(S_IXACL | 0777); @@ -351,6 +348,7 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod) u.a.g_access = (mode >> 3) & 7; u.a.o_access = mode & 7; + int ret; if (desc != -1) ret = aclx_fput (desc, SET_ACL | SET_MODE_S_BITS, type, &u.a, u.a.acl_len, mode); @@ -363,12 +361,10 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod) else if (type.u64 == ACL_NFS4) { union { nfs4_acl_int_t a; char room[128]; } u; - nfs4_ace_int_t *ace; - int ret; - u.a.aclVersion = NFS4_ACL_INT_STRUCT_VERSION; u.a.aclEntryN = 0; - ace = &u.a.aclEntry[0]; + + nfs4_ace_int_t *ace = &u.a.aclEntry[0]; { ace->flags = ACE4_ID_SPECIAL; ace->aceWho.special_whoid = ACE4_WHO_OWNER; @@ -422,6 +418,7 @@ set_acls_from_mode (const char *name, int desc, mode_t mode, bool *must_chmod) } u.a.aclLength = (char *) ace - (char *) &u.a; + int ret; if (desc != -1) ret = aclx_fput (desc, SET_ACL | SET_MODE_S_BITS, type, &u.a, u.a.aclLength, mode); @@ -453,8 +450,6 @@ context_acl_from_mode (struct permission_context *ctx) static int context_acl_from_mode (struct permission_context *ctx) { - int ret; - ctx->entries[0].a_type = USER_OBJ; ctx->entries[0].a_id = 0; /* irrelevant */ ctx->entries[0].a_perm = (ctx->mode >> 6) & 7; @@ -469,7 +464,7 @@ context_acl_from_mode (struct permission_context *ctx) ctx->entries[3].a_perm = ctx->mode & 7; ctx->count = 4; - ret = aclsort (ctx->count, 1, entries); + int ret = aclsort (ctx->count, 1, entries); if (ret > 0) abort (); return ret; @@ -564,9 +559,8 @@ set_acls (struct permission_context *ctx, const char *name, int desc, if (ctx->acl == NULL) { - acl_t acl; - /* Remove ACLs if the file has ACLs. */ + acl_t acl; if (HAVE_ACL_GET_FD && desc != -1) acl = acl_get_fd (desc); else @@ -773,7 +767,6 @@ set_permissions (struct permission_context *ctx, const char *name, int desc) _GL_UNUSED bool acls_set = false; bool early_chmod; bool must_chmod = false; - int ret = 0; #if USE_ACL # if HAVE_STATACL @@ -798,11 +791,12 @@ set_permissions (struct permission_context *ctx, const char *name, int desc) if (early_chmod) { - ret = chmod_or_fchmod (name, desc, ctx->mode); + int ret = chmod_or_fchmod (name, desc, ctx->mode); if (ret != 0) return -1; } + int ret = 0; #if USE_ACL ret = set_acls (ctx, name, desc, false, &must_chmod, &acls_set); if (! acls_set) diff --git a/lib/sha1.c b/lib/sha1.c index fd72199d2fc..14fca37b61c 100644 --- a/lib/sha1.c +++ b/lib/sha1.c @@ -253,13 +253,14 @@ sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx) while (words < endp) { - uint32_t tm; for (int t = 0; t < 16; t++) { x[t] = SWAP (*words); words++; } + uint32_t tm; + R( a, b, c, d, e, F1, K1, x[ 0] ); R( e, a, b, c, d, F1, K1, x[ 1] ); R( d, e, a, b, c, F1, K1, x[ 2] ); diff --git a/lib/sha256.c b/lib/sha256.c index 27c4f0c76f3..c57bfddf875 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -324,8 +324,8 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) + S0(x[(I-15)&0x0f]) + x[I&0x0f] \ , x[I&0x0f] = tm ) -#define R(A,B,C,D,E,F,G,H,K,M) do { t0 = SS0(A) + F2(A,B,C); \ - t1 = H + SS1(E) \ +#define R(A,B,C,D,E,F,G,H,K,M) do { uint32_t t0 = SS0(A) + F2(A,B,C); \ + uint32_t t1 = H + SS1(E) \ + F1(E,F,G) \ + K \ + M; \ @@ -334,8 +334,6 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) while (words < endp) { - uint32_t tm; - uint32_t t0, t1; /* FIXME: see sha1.c for a better implementation. */ for (int t = 0; t < 16; t++) { @@ -343,6 +341,8 @@ sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) words++; } + uint32_t tm; + R( a, b, c, d, e, f, g, h, K( 0), x[ 0] ); R( h, a, b, c, d, e, f, g, K( 1), x[ 1] ); R( g, h, a, b, c, d, e, f, K( 2), x[ 2] ); diff --git a/lib/sig2str.c b/lib/sig2str.c index d21aac1c643..5fb3b216e91 100644 --- a/lib/sig2str.c +++ b/lib/sig2str.c @@ -291,18 +291,19 @@ str2signum (char const *signame) return numname_table[i].num; { - char *endp; int rtmin = SIGRTMIN; int rtmax = SIGRTMAX; if (0 < rtmin && strncmp (signame, "RTMIN", 5) == 0) { + char *endp; long int n = strtol (signame + 5, &endp, 10); if (! *endp && 0 <= n && n <= rtmax - rtmin) return rtmin + n; } else if (0 < rtmax && strncmp (signame, "RTMAX", 5) == 0) { + char *endp; long int n = strtol (signame + 5, &endp, 10); if (! *endp && rtmin - rtmax <= n && n <= 0) return rtmax + n; @@ -340,11 +341,11 @@ sig2str (int signum, char *signame) { int rtmin = SIGRTMIN; int rtmax = SIGRTMAX; - int base, delta; if (! (rtmin <= signum && signum <= rtmax)) return -1; + int base; if (signum <= rtmin + (rtmax - rtmin) / 2) { strcpy (signame, "RTMIN"); @@ -356,7 +357,7 @@ sig2str (int signum, char *signame) base = rtmax; } - delta = signum - base; + int delta = signum - base; if (delta != 0) sprintf (signame + 5, "%+d", delta); return 0; diff --git a/lib/stat-time.c b/lib/stat-time.c index fa93e16cd95..a8ce2fcad96 100644 --- a/lib/stat-time.c +++ b/lib/stat-time.c @@ -15,7 +15,6 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define _GL_STAT_TIME_INLINE _GL_EXTERN_INLINE +#include #include "stat-time.h" diff --git a/lib/stdc_bit_width.c b/lib/stdc_bit_width.c index 27fde723f3d..0fabf1ba9a3 100644 --- a/lib/stdc_bit_width.c +++ b/lib/stdc_bit_width.c @@ -14,7 +14,6 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define _GL_STDC_BIT_WIDTH_INLINE _GL_EXTERN_INLINE +#include #include diff --git a/lib/stdc_count_ones.c b/lib/stdc_count_ones.c index 76d5dd46454..063619ce770 100644 --- a/lib/stdc_count_ones.c +++ b/lib/stdc_count_ones.c @@ -14,9 +14,8 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define _GL_STDC_COUNT_ONES_INLINE _GL_EXTERN_INLINE +#include #include #if 1500 <= _MSC_VER && (defined _M_IX86 || defined _M_X64) diff --git a/lib/stdc_leading_zeros.c b/lib/stdc_leading_zeros.c index 2597c43fc70..3d1e6f6cf14 100644 --- a/lib/stdc_leading_zeros.c +++ b/lib/stdc_leading_zeros.c @@ -14,7 +14,6 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define _GL_STDC_LEADING_ZEROS_INLINE _GL_EXTERN_INLINE +#include #include diff --git a/lib/stdc_trailing_zeros.c b/lib/stdc_trailing_zeros.c index 5d5d296c40e..12898f8ef2b 100644 --- a/lib/stdc_trailing_zeros.c +++ b/lib/stdc_trailing_zeros.c @@ -14,7 +14,6 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define _GL_STDC_TRAILING_ZEROS_INLINE _GL_EXTERN_INLINE +#include #include diff --git a/lib/stdio-consolesafe.c b/lib/stdio-consolesafe.c index 80561a6da4e..488ed8434b0 100644 --- a/lib/stdio-consolesafe.c +++ b/lib/stdio-consolesafe.c @@ -133,8 +133,8 @@ int gl_consolesafe_fprintf (FILE *restrict fp, const char *restrict format, ...) { va_list args; - char *tmpstring; va_start (args, format); + char *tmpstring; int result = vasprintf (&tmpstring, format, args); va_end (args); if (result >= 0) @@ -151,8 +151,8 @@ int gl_consolesafe_printf (const char *restrict format, ...) { va_list args; - char *tmpstring; va_start (args, format); + char *tmpstring; int result = vasprintf (&tmpstring, format, args); va_end (args); if (result >= 0) diff --git a/lib/str-two-way.h b/lib/str-two-way.h index 1da773eb70e..deb62a0971e 100644 --- a/lib/str-two-way.h +++ b/lib/str-two-way.h @@ -108,13 +108,6 @@ static size_t critical_factorization (const unsigned char *needle, size_t needle_len, size_t *period) { - /* Index of last byte of left half, or SIZE_MAX. */ - size_t max_suffix, max_suffix_rev; - size_t j; /* Index into NEEDLE for current candidate suffix. */ - size_t k; /* Offset into current period. */ - size_t p; /* Intermediate period. */ - unsigned char a, b; /* Current comparison bytes. */ - /* Special case NEEDLE_LEN of 1 or 2 (all callers already filtered out 0-length needles. */ if (needle_len < 3) @@ -133,73 +126,83 @@ critical_factorization (const unsigned char *needle, size_t needle_len, */ /* Perform lexicographic search. */ - max_suffix = SIZE_MAX; - j = 0; - k = p = 1; - while (j + k < needle_len) - { - a = CANON_ELEMENT (needle[j + k]); - b = CANON_ELEMENT (needle[max_suffix + k]); - if (a < b) - { - /* Suffix is smaller, period is entire prefix so far. */ - j += k; - k = 1; - p = j - max_suffix; - } - else if (a == b) - { - /* Advance through repetition of the current period. */ - if (k != p) - ++k; - else - { - j += p; - k = 1; - } - } - else /* b < a */ - { - /* Suffix is larger, start over from current location. */ - max_suffix = j++; - k = p = 1; - } - } - *period = p; + size_t max_suffix = /* Index of last byte of left half, or SIZE_MAX. */ + SIZE_MAX; + { + size_t j = 0; /* Index into NEEDLE for current candidate suffix. */ + size_t k = 1; /* Offset into current period. */ + size_t p = 1; /* Intermediate period. */ + while (j + k < needle_len) + { + unsigned char a = CANON_ELEMENT (needle[j + k]); + unsigned char b = CANON_ELEMENT (needle[max_suffix + k]); + if (a < b) + { + /* Suffix is smaller, period is entire prefix so far. */ + j += k; + k = 1; + p = j - max_suffix; + } + else if (a == b) + { + /* Advance through repetition of the current period. */ + if (k != p) + ++k; + else + { + j += p; + k = 1; + } + } + else /* b < a */ + { + /* Suffix is larger, start over from current location. */ + max_suffix = j++; + k = p = 1; + } + } + *period = p; + } /* Perform reverse lexicographic search. */ - max_suffix_rev = SIZE_MAX; - j = 0; - k = p = 1; - while (j + k < needle_len) - { - a = CANON_ELEMENT (needle[j + k]); - b = CANON_ELEMENT (needle[max_suffix_rev + k]); - if (b < a) - { - /* Suffix is smaller, period is entire prefix so far. */ - j += k; - k = 1; - p = j - max_suffix_rev; - } - else if (a == b) - { - /* Advance through repetition of the current period. */ - if (k != p) - ++k; - else - { - j += p; - k = 1; - } - } - else /* a < b */ - { - /* Suffix is larger, start over from current location. */ - max_suffix_rev = j++; - k = p = 1; - } - } + size_t max_suffix_rev = /* Index of last byte of left half, or SIZE_MAX. */ + SIZE_MAX; + size_t p_rev; + { + size_t j = 0; /* Index into NEEDLE for current candidate suffix. */ + size_t k = 1; /* Offset into current period. */ + size_t p = 1; /* Intermediate period. */ + while (j + k < needle_len) + { + unsigned char a = CANON_ELEMENT (needle[j + k]); + unsigned char b = CANON_ELEMENT (needle[max_suffix_rev + k]); + if (b < a) + { + /* Suffix is smaller, period is entire prefix so far. */ + j += k; + k = 1; + p = j - max_suffix_rev; + } + else if (a == b) + { + /* Advance through repetition of the current period. */ + if (k != p) + ++k; + else + { + j += p; + k = 1; + } + } + else /* a < b */ + { + /* Suffix is larger, start over from current location. */ + max_suffix_rev = j++; + k = p = 1; + } + } + p_rev = p; + } /* Choose the shorter suffix. Return the index of the first byte of the right half, rather than the last byte of the left half. @@ -217,7 +220,7 @@ critical_factorization (const unsigned char *needle, size_t needle_len, factorization. */ if (max_suffix_rev + 1 < max_suffix + 1) return max_suffix + 1; - *period = p; + *period = p_rev; return max_suffix_rev + 1; } @@ -235,15 +238,12 @@ static RETURN_TYPE _GL_ATTRIBUTE_PURE two_way_short_needle (const unsigned char *haystack, size_t haystack_len, const unsigned char *needle, size_t needle_len) { - size_t i; /* Index into current byte of NEEDLE. */ - size_t j; /* Index into current window of HAYSTACK. */ - size_t period; /* The period of the right half of needle. */ - size_t suffix; /* The index of the right half of needle. */ - /* Factor the needle into two halves, such that the left half is smaller than the global period, and the right half is periodic (with a period as large as NEEDLE_LEN - suffix). */ - suffix = critical_factorization (needle, needle_len, &period); + size_t period; /* The period of the right half of needle. */ + size_t suffix = /* The index of the right half of needle. */ + critical_factorization (needle, needle_len, &period); /* Perform the search. Each iteration compares the right half first. */ @@ -253,11 +253,12 @@ two_way_short_needle (const unsigned char *haystack, size_t haystack_len, only advance by the period, so use memory to avoid rescanning known occurrences of the period in the right half. */ size_t memory = 0; - j = 0; + size_t j = 0; /* Index into current window of HAYSTACK. */ while (AVAILABLE (haystack, haystack_len, j, needle_len)) { /* Scan for matches in right half. */ - i = MAX (suffix, memory); + size_t i = /* Index into current byte of NEEDLE. */ + MAX (suffix, memory); while (i < needle_len && (CANON_ELEMENT (needle[i]) == CANON_ELEMENT (haystack[i + j]))) ++i; @@ -287,11 +288,12 @@ two_way_short_needle (const unsigned char *haystack, size_t haystack_len, /* The two halves of needle are distinct; no extra memory is required, and any mismatch results in a maximal shift. */ period = MAX (suffix, needle_len - suffix) + 1; - j = 0; + size_t j = 0; /* Index into current window of HAYSTACK. */ while (AVAILABLE (haystack, haystack_len, j, needle_len)) { /* Scan for matches in right half. */ - i = suffix; + size_t i = /* Index into current byte of NEEDLE. */ + suffix; while (i < needle_len && (CANON_ELEMENT (needle[i]) == CANON_ELEMENT (haystack[i + j]))) ++i; @@ -329,20 +331,18 @@ static RETURN_TYPE _GL_ATTRIBUTE_PURE two_way_long_needle (const unsigned char *haystack, size_t haystack_len, const unsigned char *needle, size_t needle_len) { - size_t j; /* Index into current window of HAYSTACK. */ - size_t period; /* The period of the right half of needle. */ - size_t suffix; /* The index of the right half of needle. */ - size_t shift_table[1U << CHAR_BIT]; /* See below. */ - /* Factor the needle into two halves, such that the left half is smaller than the global period, and the right half is periodic (with a period as large as NEEDLE_LEN - suffix). */ - suffix = critical_factorization (needle, needle_len, &period); + size_t period; /* The period of the right half of needle. */ + size_t suffix = /* The index of the right half of needle. */ + critical_factorization (needle, needle_len, &period); /* Populate shift_table. For each possible byte value c, shift_table[c] is the distance from the last occurrence of c to the end of NEEDLE, or NEEDLE_LEN if c is absent from the NEEDLE. shift_table[NEEDLE[NEEDLE_LEN - 1]] contains the only 0. */ + size_t shift_table[1U << CHAR_BIT]; for (size_t i = 0; i < 1U << CHAR_BIT; i++) shift_table[i] = needle_len; for (size_t i = 0; i < needle_len; i++) @@ -356,13 +356,13 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len, only advance by the period, so use memory to avoid rescanning known occurrences of the period in the right half. */ size_t memory = 0; - size_t shift; - j = 0; + size_t j = 0; /* Index into current window of HAYSTACK. */ while (AVAILABLE (haystack, haystack_len, j, needle_len)) { /* Check the last byte first; if it does not match, then shift to the next possible match location. */ - shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])]; + size_t shift = + shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])]; if (0 < shift) { if (memory && shift < period) @@ -409,14 +409,14 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len, { /* The two halves of needle are distinct; no extra memory is required, and any mismatch results in a maximal shift. */ - size_t shift; period = MAX (suffix, needle_len - suffix) + 1; - j = 0; + size_t j = 0; /* Index into current window of HAYSTACK. */ while (AVAILABLE (haystack, haystack_len, j, needle_len)) { /* Check the last byte first; if it does not match, then shift to the next possible match location. */ - shift = shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])]; + size_t shift = + shift_table[CANON_ELEMENT (haystack[j + needle_len - 1])]; if (0 < shift) { j += shift; diff --git a/lib/strftime.c b/lib/strftime.c index 291c650b970..16e1cb3bc65 100644 --- a/lib/strftime.c +++ b/lib/strftime.c @@ -1356,13 +1356,12 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) an error, or come back to the initial shift state. */ { mbstate_t mbstate = mbstate_zero; - size_t len = 0; - size_t fsize; if (! format_end) format_end = f + strlen (f) + 1; - fsize = format_end - f; + size_t fsize = format_end - f; + size_t len = 0; do { size_t bytes = mbrlen (f + len, fsize - len, &mbstate); @@ -2086,12 +2085,9 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) case L_('s'): /* GNU extension. */ { - struct tm ltm; - time_t t; - - ltm = *tp; + struct tm ltm = *tp; ltm.tm_yday = -1; - t = mktime_z (tz, <m); + time_t t = mktime_z (tz, <m); if (ltm.tm_yday < 0) { errno = EOVERFLOW; @@ -2359,9 +2355,6 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) { int diff; - int hour_diff; - int min_diff; - int sec_diff; #if HAVE_STRUCT_TM_TM_GMTOFF diff = tp->tm_gmtoff; #else @@ -2369,14 +2362,13 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) diff = 0; else { - struct tm gtm; - struct tm ltm; - time_t lt; - - ltm = *tp; + struct tm ltm = *tp; ltm.tm_wday = -1; - lt = mktime_z (tz, <m); - if (ltm.tm_wday < 0 || ! localtime_rz (0, <, >m)) + time_t lt = mktime_z (tz, <m); + if (ltm.tm_wday < 0) + break; + struct tm gtm; + if (! localtime_rz (0, <, >m)) break; diff = tm_diff (<m, >m); } @@ -2390,9 +2382,9 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) 0, tp) == '-'); } - hour_diff = diff / 60 / 60; - min_diff = diff / 60 % 60; - sec_diff = diff % 60; + int hour_diff = diff / 60 / 60; + int min_diff = diff / 60 % 60; + int sec_diff = diff % 60; switch (colons) { diff --git a/lib/string.c b/lib/string.c index cce2eac9c06..602bb7383e8 100644 --- a/lib/string.c +++ b/lib/string.c @@ -14,7 +14,6 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define _GL_STRING_INLINE _GL_EXTERN_INLINE +#include #include diff --git a/lib/strtol.c b/lib/strtol.c index 954ba67a4a7..68ce07d0819 100644 --- a/lib/strtol.c +++ b/lib/strtol.c @@ -212,14 +212,6 @@ INT INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, int base GROUP_PARAM_PROTO LOCALE_PARAM_PROTO) { - int negative; - register unsigned LONG int cutoff; - register unsigned int cutlim; - register unsigned LONG int i; - register const STRING_TYPE *s; - const STRING_TYPE *save, *end; - int overflow; - #ifdef USE_NUMBER_GROUPING # ifdef USE_IN_EXTENDED_LOCALE_MODEL struct locale_data *current = loc->__locales[LC_NUMERIC]; @@ -257,7 +249,8 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, return 0; } - save = s = nptr; + register const STRING_TYPE *s = nptr; + const STRING_TYPE *save = s; /* Skip white space. */ while (ISSPACE (*s)) @@ -266,6 +259,7 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, goto noconv; /* Check for a sign. */ + int negative; if (*s == L_('-')) { negative = 1; @@ -301,6 +295,7 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, /* Save the pointer so we can check later if anything happened. */ save = s; + const STRING_TYPE *end; #ifdef USE_NUMBER_GROUPING if (group) { @@ -320,11 +315,11 @@ INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr, #endif end = NULL; - cutoff = STRTOL_ULONG_MAX / (unsigned LONG int) base; - cutlim = STRTOL_ULONG_MAX % (unsigned LONG int) base; + register unsigned LONG int cutoff = STRTOL_ULONG_MAX / (unsigned LONG int) base; + register unsigned int cutlim = STRTOL_ULONG_MAX % (unsigned LONG int) base; - overflow = 0; - i = 0; + int overflow = 0; + register unsigned LONG int i = 0; for (UCHAR_TYPE c = *s; c != L_('\0'); c = *++s) { if (s == end) diff --git a/lib/tempname.c b/lib/tempname.c index cd16daf3335..3fa6b901b6b 100644 --- a/lib/tempname.c +++ b/lib/tempname.c @@ -189,9 +189,6 @@ int try_tempname_len (char *tmpl, int suffixlen, void *args, int (*tryfunc) (char *, void *), size_t x_suffix_len) { - size_t len; - char *XXXXXX; - int fd = -1; int saved_errno = errno; /* A lower bound on the number of temporary files to attempt to @@ -224,7 +221,7 @@ try_tempname_len (char *tmpl, int suffixlen, void *args, random_value const biased_min = RANDOM_VALUE_MAX - RANDOM_VALUE_MAX % BASE_62_POWER; - len = strlen (tmpl); + size_t len = strlen (tmpl); if (len < x_suffix_len + suffixlen || strspn (&tmpl[len - x_suffix_len - suffixlen], "X") < x_suffix_len) { @@ -233,7 +230,7 @@ try_tempname_len (char *tmpl, int suffixlen, void *args, } /* This is where the Xs start. */ - XXXXXX = &tmpl[len - x_suffix_len - suffixlen]; + char *XXXXXX = &tmpl[len - x_suffix_len - suffixlen]; for (unsigned int count = 0; count < attempts; ++count) { @@ -254,7 +251,7 @@ try_tempname_len (char *tmpl, int suffixlen, void *args, vdigits--; } - fd = tryfunc (tmpl, args); + int fd = tryfunc (tmpl, args); if (fd >= 0) { __set_errno (saved_errno); diff --git a/lib/timespec-add.c b/lib/timespec-add.c index 3e154f24853..a16cb05e828 100644 --- a/lib/timespec-add.c +++ b/lib/timespec-add.c @@ -32,8 +32,8 @@ timespec_add (struct timespec a, struct timespec b) int nssum = a.tv_nsec + b.tv_nsec; int carry = TIMESPEC_HZ <= nssum; time_t rs; - int rns; bool v = ckd_add (&rs, a.tv_sec, b.tv_sec); + int rns; if (v == ckd_add (&rs, rs, carry)) rns = nssum - TIMESPEC_HZ * carry; else diff --git a/lib/timespec-sub.c b/lib/timespec-sub.c index 7cde18be90c..df51a49c215 100644 --- a/lib/timespec-sub.c +++ b/lib/timespec-sub.c @@ -33,8 +33,8 @@ timespec_sub (struct timespec a, struct timespec b) int nsdiff = a.tv_nsec - b.tv_nsec; int borrow = nsdiff < 0; time_t rs; - int rns; bool v = ckd_sub (&rs, a.tv_sec, b.tv_sec); + int rns; if (v == ckd_sub (&rs, rs, borrow)) rns = nsdiff + TIMESPEC_HZ * borrow; else diff --git a/lib/timespec.c b/lib/timespec.c index 9ab11e5cc5d..261848d6116 100644 --- a/lib/timespec.c +++ b/lib/timespec.c @@ -15,7 +15,6 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define _GL_TIMESPEC_INLINE _GL_EXTERN_INLINE +#include #include "timespec.h" diff --git a/lib/u64.c b/lib/u64.c index 9bf45b29121..8cfd7dfdc1a 100644 --- a/lib/u64.c +++ b/lib/u64.c @@ -15,8 +15,8 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include - #define _GL_U64_INLINE _GL_EXTERN_INLINE +#include #include "u64.h" + typedef int dummy; diff --git a/lib/utimens.c b/lib/utimens.c index 0387e9f10e9..5ec77958bb9 100644 --- a/lib/utimens.c +++ b/lib/utimens.c @@ -19,10 +19,10 @@ /* derived from a function in touch.c */ +#define _GL_UTIMENS_INLINE _GL_EXTERN_INLINE #include /* Specification. */ -#define _GL_UTIMENS_INLINE _GL_EXTERN_INLINE #include "utimens.h" #include @@ -105,13 +105,13 @@ is_valid_timespecs (struct timespec const timespec[2]) static int validate_timespec (struct timespec timespec[2]) { - int result = 0; - int utime_omit_count = 0; if (!is_valid_timespecs (timespec)) { errno = EINVAL; return -1; } + int result = 0; + int utime_omit_count = 0; /* Work around Linux kernel 2.6.25 bug, where utimensat fails with EINVAL if tv_sec is not 0 when using the flag values of tv_nsec. Flag a Linux kernel 2.6.32 bug, where an mtime of UTIME_OMIT @@ -184,7 +184,6 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2]) struct timespec adjusted_timespec[2]; struct timespec *ts = timespec ? adjusted_timespec : NULL; int adjustment_needed = 0; - struct stat st; if (ts) { @@ -221,6 +220,8 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2]) fsync (fd); #endif + struct stat st; + /* POSIX 2008 added two interfaces to set file timestamps with nanosecond resolution; newer Linux implements both functions via a single syscall. We provide a fallback for ENOSYS (for example, @@ -319,18 +320,14 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2]) */ if (0 <= fd) { - HANDLE handle; - FILETIME current_time; - FILETIME last_access_time; - FILETIME last_write_time; - - handle = (HANDLE) _get_osfhandle (fd); + HANDLE handle = (HANDLE) _get_osfhandle (fd); if (handle == INVALID_HANDLE_VALUE) { errno = EBADF; return -1; } + FILETIME current_time; if (ts == NULL || ts[0].tv_nsec == UTIME_NOW || ts[1].tv_nsec == UTIME_NOW) { /* GetSystemTimeAsFileTime @@ -341,6 +338,7 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2]) GetSystemTimeAsFileTime (¤t_time); } + FILETIME last_access_time; if (ts == NULL || ts[0].tv_nsec == UTIME_NOW) { last_access_time = current_time; @@ -358,6 +356,7 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2]) last_access_time.dwHighDateTime = time_since_16010101 >> 32; } + FILETIME last_write_time; if (ts == NULL || ts[1].tv_nsec == UTIME_NOW) { last_write_time = current_time; @@ -468,10 +467,11 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2]) time_t adiff = st.st_atime - t[0].tv_sec; time_t mdiff = st.st_mtime - t[1].tv_sec; - struct timeval *tt = NULL; struct timeval truncated_timeval[2]; truncated_timeval[0] = t[0]; truncated_timeval[1] = t[1]; + + struct timeval *tt = NULL; if (abig && adiff == 1 && get_stat_atime_ns (&st) == 0) { tt = truncated_timeval; @@ -567,7 +567,6 @@ lutimens (char const *file, struct timespec const timespec[2]) struct timespec adjusted_timespec[2]; struct timespec *ts = timespec ? adjusted_timespec : NULL; int adjustment_needed = 0; - struct stat st; if (ts) { @@ -578,6 +577,8 @@ lutimens (char const *file, struct timespec const timespec[2]) if (adjustment_needed < 0) return -1; + struct stat st; + /* The Linux kernel did not support symlink timestamps until utimensat, in version 2.6.22, so we don't need to mimic fdutimens' worry about buggy NFS clients. But we do have to @@ -653,7 +654,6 @@ lutimens (char const *file, struct timespec const timespec[2]) { struct timeval timeval[2]; struct timeval *t; - int result; if (ts) { timeval[0] = (struct timeval) { .tv_sec = ts[0].tv_sec, @@ -665,7 +665,7 @@ lutimens (char const *file, struct timespec const timespec[2]) else t = NULL; - result = lutimes (file, t); + int result = lutimes (file, t); if (result == 0 || errno != ENOSYS) return result; } diff --git a/lib/utimensat.c b/lib/utimensat.c index fcf2d27eb3e..6830c58fa64 100644 --- a/lib/utimensat.c +++ b/lib/utimensat.c @@ -85,7 +85,6 @@ rpl_utimensat (int fd, char const *file, struct timespec const times[2], static int utimensat_works_really; /* 0 = unknown, 1 = yes, -1 = no. */ if (0 <= utimensat_works_really) { - int result; # if defined __linux__ || defined __sun || defined __NetBSD__ struct stat st; /* As recently as Linux kernel 2.6.32 (Dec 2009), several file @@ -167,7 +166,7 @@ rpl_utimensat (int fd, char const *file, struct timespec const times[2], } # endif # endif - result = utimensat (fd, file, times, flag); + int result = utimensat (fd, file, times, flag); /* Linux kernel 2.6.25 has a bug where it returns EINVAL for UTIME_NOW or UTIME_OMIT with non-zero tv_sec, which local_utimensat works around. Meanwhile, EINVAL for a bad diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index 5bb06bed4d3..7ec965c0e45 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -1,5 +1,5 @@ # gnulib-common.m4 -# serial 114 +# serial 115 dnl Copyright (C) 2007-2025 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -414,16 +414,17 @@ AC_DEFUN([gl_COMMON_BODY], [ #endif /* _GL_ATTRIBUTE_CONST declares: - It is OK for a compiler to move calls to the function and to omit - calls to the function if another call has the same arguments or the - result is not used. - This attribute is safe for a function that neither depends on - nor affects state, and always returns exactly once - + It is OK for a compiler to move a call, or omit a duplicate call + and reuse a cached return value, even if the state changes between calls. + It is also OK to omit a call if the result is not used. + This attribute is safe if the function does not change observable state, + returns a value determined solely by its arguments' values + without examining state, and always returns exactly once - e.g., does not raise an exception, call longjmp, or loop forever. (This attribute is stricter than _GL_ATTRIBUTE_PURE because the function cannot observe state. It is stricter than _GL_ATTRIBUTE_UNSEQUENCED because the function must return exactly - once and cannot depend on state addressed by its arguments.) */ + once and cannot access state addressed by its arguments.) */ /* Applies to: functions. */ #ifndef _GL_ATTRIBUTE_CONST # if _GL_HAS_ATTRIBUTE (const) @@ -744,15 +745,16 @@ AC_DEFUN([gl_COMMON_BODY], [ #endif /* _GL_ATTRIBUTE_PURE declares: - It is OK for a compiler to move calls to the function and to omit - calls to the function if another call has the same arguments or the - result is not used, and if observable state is the same. - This attribute is safe for a function that does not affect observable state - and always returns exactly once. + It is OK for a compiler to move a call, or omit a duplicate call + and reuse a cached return value, if observable state is the same. + It is also OK to omit a call if the return value is not used. + This attribute is safe if the function does not change observable state, + returns a value determined solely by its arguments's values + together with observable state, and always returns exactly once. (This attribute is looser than _GL_ATTRIBUTE_CONST because the function can depend on observable state. It is stricter than _GL_ATTRIBUTE_REPRODUCIBLE because the function must return exactly - once and cannot affect state addressed by its arguments.) */ + once and cannot change state addressed by its arguments.) */ /* Applies to: functions. */ #ifndef _GL_ATTRIBUTE_PURE # if _GL_HAS_ATTRIBUTE (pure) @@ -763,16 +765,17 @@ AC_DEFUN([gl_COMMON_BODY], [ #endif /* _GL_ATTRIBUTE_REPRODUCIBLE declares: - It is OK for a compiler to move calls to the function and to omit duplicate - calls to the function with the same arguments, so long as the state - addressed by its arguments is the same and is updated in time for - the rest of the program. - This attribute is safe for a function that is effectless and idempotent; see - ISO C 23 § 6.7.13.8 for a definition of these terms. + It is OK for a compiler to move a call, or omit a duplicate call + and reuse a cached value returned either directly or indirectly + via a pointer argument, if other observable state is the same; + however, these pointer arguments cannot alias. + This attribute is safe for a function that is effectless and idempotent; + see ISO C 23 § 6.7.13.8 for a definition of these terms. (This attribute is looser than _GL_ATTRIBUTE_UNSEQUENCED because - the function need not be stateless and idempotent. It is looser - than _GL_ATTRIBUTE_PURE because the function need not return - exactly once and can affect state addressed by its arguments.) + the function need not be stateless or independent. It is looser + from _GL_ATTRIBUTE_PURE because the function need not return + exactly once, and it can change state addressed by its pointer arguments + that do not alias.) See also and . ATTENTION! Efforts are underway to change the meaning of this attribute. @@ -816,16 +819,17 @@ AC_DEFUN([gl_COMMON_BODY], [ #endif /* _GL_ATTRIBUTE_UNSEQUENCED declares: - It is OK for a compiler to move calls to the function and to omit duplicate - calls to the function with the same arguments, so long as the state - addressed by its arguments is the same. + It is OK for a compiler to move a call, or omit a duplicate call + and reuse a cached return value, addressed by its arguments is the same. This attribute is safe for a function that is effectless, idempotent, stateless, and independent; see ISO C 23 § 6.7.13.8 for a definition of these terms. (This attribute is stricter than _GL_ATTRIBUTE_REPRODUCIBLE because - the function must be stateless and independent. It is looser than + the function must be stateless and independent. It differs from _GL_ATTRIBUTE_CONST because the function need not return exactly - once and can depend on state addressed by its arguments.) + once and can depend on state accessed via its pointer arguments + that do not alias, or on other state that happens to have the + same value for all calls to the function.) See also and . ATTENTION! Efforts are underway to change the meaning of this attribute. commit 976143651b832ca0dcaf1d15e41eb7424aec4c90 Author: Roi Martin Date: Fri Dec 12 15:33:39 2025 +0100 Fix interactive call to 'prepare-user-lisp' When called interactively with a prefix argument, 'prepare-user-lisp' throws a "Wrong type argument: stringp, (4)" error. This happens because the list passed to the interactive specification is missing one argument and 'current-prefix-arg' is assigned to AUTOLOAD-FILE instead of FORCE. * lisp/startup.el (prepare-user-lisp): Fix list passed to 'interactive'. (Bug#79996) diff --git a/lisp/startup.el b/lisp/startup.el index 41e08d4d2bd..c455eb73814 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -1245,7 +1245,7 @@ If AUTOLOAD-FILE is nil, store the autoload data in a file next to DIR. If FORCE is non-nil, or if invoked interactively with a prefix argument, re-create the entire autoload file and byte-compile everything unconditionally." - (interactive (list nil current-prefix-arg)) + (interactive (list nil nil current-prefix-arg)) (unless (file-directory-p user-lisp-directory) (error "No such directory: %S" user-lisp-directory)) (unless autoload-file commit aa5a9df828008a69b3f5890a689282911714a06c Author: Stefan Monnier Date: Fri Dec 12 15:29:13 2025 -0500 Editorconfig: Merge a few more changes from upstream * lisp/editorconfig-core.el: Fix up leading comment. (editorconfig-core-get-properties-hash): Remove unused `confversion` arg. * lisp/editorconfig-fnmatch.el (editorconfig-fnmatch--cache-hashtable): Use `defconst`. (editorconfig-fnmatch--do-translate): Don't escape `,` or `-` in regexps. * lisp/editorconfig.el (editorconfig-indentation-alist): Remove redundant entries for `ess-mode` and `terra-mode`. diff --git a/lisp/editorconfig-core.el b/lisp/editorconfig-core.el index 46fdcf04385..bf7f0ef3def 100644 --- a/lisp/editorconfig-core.el +++ b/lisp/editorconfig-core.el @@ -39,18 +39,16 @@ ;; and fallback to this library if not found. ;; If you always want to use this library, add following lines to your init.el: -;; (setq editorconfig-get-properties-function -;; 'editorconfig-core-get-properties-hash) - - ;; Functions -;; editorconfig-core-get-properties-hash (&optional file confname confversion) +;; editorconfig-core-get-properties-hash (&optional file confname) ;; Get EditorConfig properties for FILE. -;; This function is almost same as `editorconfig-core-get-properties', but -;; returns hash object instead. +;; If FILE is not given, use currently visiting file. +;; Give CONFNAME for basename of config file other than .editorconfig. + +;; This functions returns hash table of properties' values. ;;; Code: @@ -95,11 +93,10 @@ When the same key exists in both two hashes, values of UPDATE takes precedence." (maphash (lambda (key value) (puthash key value into)) update) into) -(defun editorconfig-core-get-properties-hash (&optional file confname confversion) +(defun editorconfig-core-get-properties-hash (&optional file confname) "Get EditorConfig properties for FILE. If FILE is not given, use currently visiting file. Give CONFNAME for basename of config file other than .editorconfig. -If need to specify config format version, give CONFVERSION. This function is almost same as `editorconfig-core-get-properties', but returns hash object instead." @@ -108,7 +105,6 @@ hash object instead." buffer-file-name (error "FILE is not given and `buffer-file-name' is nil")))) (setq confname (or confname ".editorconfig")) - (setq confversion (or confversion "0.12.0")) (let ((result (make-hash-table))) (dolist (handle (editorconfig-core--get-handles (file-name-directory file) confname)) @@ -123,35 +119,6 @@ hash object instead." (when-let* ((val (gethash key result))) (puthash key (downcase val) result))) - ;; Add indent_size property - ;; FIXME: Why? Which part of the spec requires that? - ;;(let ((v-indent-size (gethash 'indent_size result)) - ;; (v-indent-style (gethash 'indent_style result))) - ;; (when (and (not v-indent-size) - ;; (string= v-indent-style "tab") - ;; ;; If VERSION < 0.9.0, indent_size should have no default value - ;; (version<= "0.9.0" - ;; confversion)) - ;; (puthash 'indent_size - ;; "tab" - ;; result))) - ;; Add tab_width property - ;; FIXME: Why? Which part of the spec requires that? - ;;(let ((v-indent-size (gethash 'indent_size result)) - ;; (v-tab-width (gethash 'tab_width result))) - ;; (when (and v-indent-size - ;; (not v-tab-width) - ;; (not (string= v-indent-size "tab"))) - ;; (puthash 'tab_width v-indent-size result))) - ;; Update indent-size property - ;; FIXME: Why? Which part of the spec requires that? - ;;(let ((v-indent-size (gethash 'indent_size result)) - ;; (v-tab-width (gethash 'tab_width result))) - ;; (when (and v-indent-size - ;; v-tab-width - ;; (string= v-indent-size "tab")) - ;; (puthash 'indent_size v-tab-width result))) - result)) (provide 'editorconfig-core) diff --git a/lisp/editorconfig-fnmatch.el b/lisp/editorconfig-fnmatch.el index 2e6ae466f43..7664ce23d17 100644 --- a/lisp/editorconfig-fnmatch.el +++ b/lisp/editorconfig-fnmatch.el @@ -1,6 +1,6 @@ ;;; editorconfig-fnmatch.el --- Glob pattern matching -*- lexical-binding: t -*- -;; Copyright (C) 2011-2025 Free Software Foundation, Inc. +;; Copyright (C) 2011-2025 Free Software Foundation, Inc. ;; Author: EditorConfig Team ;; Package: editorconfig @@ -55,13 +55,9 @@ (require 'cl-lib) -(defvar editorconfig-fnmatch--cache-hashtable - nil +(defconst editorconfig-fnmatch--cache-hashtable ;; Clear cache on file reload. + (make-hash-table :test 'equal) "Cache of shell pattern and its translation.") -;; Clear cache on file reload -(setq editorconfig-fnmatch--cache-hashtable - (make-hash-table :test 'equal)) - (defconst editorconfig-fnmatch--left-brace-regexp "\\(^\\|[^\\]\\){" @@ -147,7 +143,7 @@ translation is found for PATTERN." (while (< index length) (if (and (not is-escaped) - (string-match "[^]\\*?[{},/-]+" + (string-match "[^]\\*?[{},/]+" ;;(string-match "[^]\\*?[{},/\\-]+" "?.a") pattern index) @@ -203,8 +199,6 @@ translation is found for PATTERN." "[^") "["))))) - (?- (if in-brackets "-" "\\-")) - (?\] (setq in-brackets nil) "]") (?\{ @@ -249,7 +243,7 @@ translation is found for PATTERN." (?, (if (and (> brace-level 0) (not is-escaped)) - "\\|" "\\,")) + "\\|" ",")) (?\} (if (and (> brace-level 0) diff --git a/lisp/editorconfig.el b/lisp/editorconfig.el index 42ff3038b92..8978e6da96b 100644 --- a/lisp/editorconfig.el +++ b/lisp/editorconfig.el @@ -146,7 +146,6 @@ This hook will be run even when there are no matching sections in (d-mode c-basic-offset) (elixir-ts-mode elixir-ts-indent-offset) (emacs-lisp-mode . editorconfig--get-indentation-lisp-mode) - (ess-mode ess-indent-offset) (f90-mode f90-associate-indent f90-continuation-indent f90-critical-indent @@ -211,7 +210,6 @@ This hook will be run even when there are no matching sections in (scala-mode scala-indent:step) (scss-mode css-indent-offset) (swift-mode swift-mode:basic-offset) - (terra-mode terra-indent-level) (tcl-mode tcl-indent-level tcl-continued-indent-level) (toml-ts-mode toml-ts-mode-indent-offset) commit 96bb95c8cc9f2640867d3e7592edb546e8853854 Author: lolbinarycat Date: Fri Dec 12 15:26:30 2025 -0500 editorconfig-fnmatch: fix ** globs (#374) Cherypick of upstream commit 4af10445fcdf1c9dfa7af4f9e5bec59e8a759d6f diff --git a/lisp/editorconfig-fnmatch.el b/lisp/editorconfig-fnmatch.el index c230a2384c7..2e6ae466f43 100644 --- a/lisp/editorconfig-fnmatch.el +++ b/lisp/editorconfig-fnmatch.el @@ -166,7 +166,9 @@ translation is found for PATTERN." (setq pos index) (if (and (< pos length) (= (aref pattern pos) ?*)) - ".*" + (progn + (setq index (1+ index)) + ".*") "[^/]*")) (?? "[^/]") commit 55b610490bfc67a080f78b972ce0736cdd853226 Author: Mattias Engdegård Date: Fri Dec 12 16:07:11 2025 +0100 * lisp/cus-start.el: Better unbound variable filter. Remove (almost) all regexp matching and the need for saving match data. Signal an error for unbound variables instead of a timid message, so that it's certain to be noticed. diff --git a/lisp/cus-start.el b/lisp/cus-start.el index 772d2093094..fb16c56cf10 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el @@ -887,66 +887,63 @@ since it could result in memory overflow and make Emacs crash." (pcase-dolist (`(,symbol ,group ,type ,version . ,rest) builtin-cus-vars) (if (not (boundp symbol)) ;; If variables are removed from C code, give an error here! - (let ((native-p (save-match-data + (let ((native-p ;; Don't complain about missing variables which are ;; irrelevant to this platform. - (cond - ((string-match "\\`dos-" (symbol-name symbol)) - (eq system-type 'ms-dos)) - ((string-match "\\`w32-" (symbol-name symbol)) - (eq system-type 'windows-nt)) - ((string-match "\\`ns-" (symbol-name symbol)) - (featurep 'ns)) - ((string-match "\\`haiku-" (symbol-name symbol)) - (featurep 'haiku)) - ((eq symbol 'process-error-pause-time) - (not (eq system-type 'ms-dos))) - ((eq symbol 'x-gtk-use-native-input) - (and (featurep 'x) - (featurep 'gtk))) - ((string-match "\\`x-.*gtk" (symbol-name symbol)) - (featurep 'gtk)) - ((string-match "clipboard-manager" (symbol-name symbol)) - (boundp 'x-select-enable-clipboard-manager)) - ((or (equal "scroll-bar-adjust-thumb-portion" - (symbol-name symbol)) - (equal "x-scroll-event-delta-factor" - (symbol-name symbol)) - (equal "x-dnd-disable-motif-drag" - (symbol-name symbol)) - (equal "x-auto-preserve-selections" - (symbol-name symbol))) - (featurep 'x)) - ((string-match "\\`x-" (symbol-name symbol)) - (fboundp 'x-create-frame)) - ((string-match "selection" (symbol-name symbol)) - (fboundp 'x-selection-exists-p)) - ((string-match "fringe" (symbol-name symbol)) - (boundp 'fringe-bitmaps)) - ((string-match "\\`imagemagick" (symbol-name symbol)) - (fboundp 'imagemagick-types)) - ((equal "font-use-system-font" (symbol-name symbol)) - (featurep 'system-font-setting)) - ;; Conditioned on x-create-frame, because that's - ;; the condition for loadup.el to preload tool-bar.el. - ((string-match "tool-bar-" (symbol-name symbol)) - (fboundp 'x-create-frame)) - ((string-match "tab-bar-" (symbol-name symbol)) - (fboundp 'x-create-frame)) - ((string-match "image-" (symbol-name symbol)) - (fboundp 'x-create-frame)) - ((equal "vertical-centering-font-regexp" - (symbol-name symbol)) - ;; Any function from fontset.c will do. - (fboundp 'new-fontset)) - ((string-match "xwidget-" (symbol-name symbol)) - (boundp 'xwidget-internal)) - ((string-match "treesit-" (symbol-name symbol)) - ;; Any function from treesit.c will do. - (fboundp 'treesit-language-available-p)) - (t t))))) + (let ((sym-name (symbol-name symbol))) + (cond + ((string-prefix-p "dos-" sym-name) + (eq system-type 'ms-dos)) + ((string-prefix-p "w32-" sym-name) + (eq system-type 'windows-nt)) + ((string-prefix-p "ns-" sym-name) + (featurep 'ns)) + ((string-prefix-p "haiku-" sym-name) + (featurep 'haiku)) + ((eq symbol 'process-error-pause-time) + (not (eq system-type 'ms-dos))) + ((eq symbol 'x-gtk-use-native-input) + (and (featurep 'x) + (featurep 'gtk))) + ((string-match-p "\\`x-.*gtk" sym-name) + (featurep 'gtk)) + ((string-search "clipboard-manager" sym-name) + (boundp 'x-select-enable-clipboard-manager)) + ((memq symbol + '(scroll-bar-adjust-thumb-portion + x-scroll-event-delta-factor + x-dnd-disable-motif-drag + x-auto-preserve-selections)) + (featurep 'x)) + ((string-prefix-p "x-" sym-name) + (fboundp 'x-create-frame)) + ((string-search "selection" sym-name) + (fboundp 'x-selection-exists-p)) + ((string-search "fringe" sym-name) + (boundp 'fringe-bitmaps)) + ((string-prefix-p "imagemagick" sym-name) + (fboundp 'imagemagick-types)) + ((eq symbol 'font-use-system-font) + (featurep 'system-font-setting)) + ;; Conditioned on x-create-frame, because that's + ;; the condition for loadup.el to preload tool-bar.el. + ((string-prefix-p "tool-bar-" sym-name) + (fboundp 'x-create-frame)) + ((string-prefix-p "tab-bar-" sym-name) + (fboundp 'x-create-frame)) + ((string-prefix-p "image-" sym-name) + (fboundp 'x-create-frame)) + ((eq symbol 'vertical-centering-font-regexp) + ;; Any function from fontset.c will do. + (fboundp 'new-fontset)) + ((string-prefix-p "xwidget-" sym-name) + (boundp 'xwidget-internal)) + ((string-prefix-p "treesit-" sym-name) + ;; Any function from treesit.c will do. + (fboundp 'treesit-language-available-p)) + (t t))))) (when native-p - (message "Note, built-in variable `%S' not bound" symbol))) + (error "built-in variable `%S' not bound" symbol))) ;; Save the standard value, unless we already did. (unless (get symbol 'standard-value) commit 8158c4c43acd3a24a9c75c41fd054ca1edd09e30 Author: Mattias Engdegård Date: Fri Dec 12 18:50:48 2025 +0100 * lisp/cus-start.el: Clean up. Avoid computing things unless needed. Use a slightly more modern elisp style with fewer variable assignments. diff --git a/lisp/cus-start.el b/lisp/cus-start.el index dc213234c9f..772d2093094 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el @@ -41,34 +41,20 @@ ;; else as well, so let's just not bother. )) -;; Elements of this list have the form: -;; SYMBOL GROUP TYPE VERSION REST... -;; SYMBOL is the name of the variable. -;; GROUP is the custom group to which it belongs (may also be a list -;; of groups) -;; TYPE is the defcustom :type. -;; VERSION is the defcustom :version (or nil). -;; REST is a set of :KEYWORD VALUE pairs. Accepted :KEYWORDs are: -;; :standard - standard value for SYMBOL (else use current value) -;; :set - custom-set property -;; :risky - risky-local-variable property -;; :safe - safe-local-variable property -;; :tag - custom-tag property -(let (standard - native-p prop propval - ;; This function turns a value - ;; into an expression which produces that value. - (quoter (lambda (sexp) - ;; FIXME: We'd like to use macroexp-quote here, but cus-start - ;; is loaded too early in loadup.el for that. - (if (or (memq sexp '(t nil)) - (keywordp sexp) - (and (listp sexp) - (memq (car sexp) '(lambda))) - (stringp sexp) - (numberp sexp)) - sexp - (list 'quote sexp)))) +(let* ((quoter + ;; This function turns a value + ;; into an expression which produces that value. + (lambda (sexp) + ;; FIXME: We'd like to use macroexp-quote here, but cus-start + ;; is loaded too early in loadup.el for that. + (if (or (memq sexp '(t nil)) + (keywordp sexp) + (and (listp sexp) + (memq (car sexp) '(lambda))) + (stringp sexp) + (numberp sexp)) + sexp + (list 'quote sexp)))) (cursor-type-types '(choice (const :tag "Frame default" t) @@ -82,9 +68,21 @@ (const :tag "Horizontal bar" hbar) (cons :tag "Horizontal bar with specified height" (const hbar) integer) - (const :tag "None "nil)))) - (pcase-dolist - (`(,symbol ,group ,type ,version . ,rest) + (const :tag "None "nil))) + (builtin-cus-vars + ;; Elements of this list have the form: + ;; SYMBOL GROUP TYPE VERSION REST... + ;; SYMBOL is the name of the variable. + ;; GROUP is the custom group to which it belongs (may also be a list + ;; of groups) + ;; TYPE is the defcustom :type. + ;; VERSION is the defcustom :version (or nil). + ;; REST is a set of :KEYWORD VALUE pairs. Accepted :KEYWORDs are: + ;; :standard - standard value for SYMBOL (else use current value) + ;; :set - custom-set property + ;; :risky - risky-local-variable property + ;; :safe - safe-local-variable property + ;; :tag - custom-tag property `(;; alloc.c (gc-cons-threshold alloc integer) (gc-cons-percentage alloc float) @@ -885,15 +883,13 @@ since it could result in memory overflow and make Emacs crash." (haiku-debug-on-fatal-error debug boolean "29.1") ;; haikufns.c (haiku-use-system-tooltips tooltip boolean "29.1"))) - (setq ;; If we did not specify any standard value expression above, - ;; use the current value as the standard value. - standard (if (setq prop (memq :standard rest)) - (cadr prop) - (if (default-boundp symbol) - (funcall quoter (default-value symbol)))) - ;; Don't complain about missing variables which are - ;; irrelevant to this platform. - native-p (save-match-data + ) + (pcase-dolist (`(,symbol ,group ,type ,version . ,rest) builtin-cus-vars) + (if (not (boundp symbol)) + ;; If variables are removed from C code, give an error here! + (let ((native-p (save-match-data + ;; Don't complain about missing variables which are + ;; irrelevant to this platform. (cond ((string-match "\\`dos-" (symbol-name symbol)) (eq system-type 'ms-dos)) @@ -948,21 +944,29 @@ since it could result in memory overflow and make Emacs crash." ((string-match "treesit-" (symbol-name symbol)) ;; Any function from treesit.c will do. (fboundp 'treesit-language-available-p)) - (t t)))) - (if (not (boundp symbol)) - ;; If variables are removed from C code, give an error here! - (and native-p - (message "Note, built-in variable `%S' not bound" symbol)) + (t t))))) + (when native-p + (message "Note, built-in variable `%S' not bound" symbol))) + ;; Save the standard value, unless we already did. - (or (get symbol 'standard-value) - (put symbol 'standard-value (list standard))) + (unless (get symbol 'standard-value) + (let* ((prop (memq :standard rest)) + (standard + ;; If we did not specify any standard value expression above, + ;; use the current value as the standard value. + (cond (prop (cadr prop)) + ((default-boundp symbol) + (funcall quoter (default-value symbol)))))) + (put symbol 'standard-value (list standard)))) + ;; We need these properties independent of whether cus-start is loaded. - (if (setq prop (memq :safe rest)) - (put symbol 'safe-local-variable (cadr prop))) - (if (setq prop (memq :risky rest)) - (put symbol 'risky-local-variable (cadr prop))) - (if (setq prop (memq :set rest)) - (put symbol 'custom-set (cadr prop))) + (let ((safe (memq :safe rest)) + (risky (memq :risky rest)) + (set (memq :set rest))) + (when safe (put symbol 'safe-local-variable (cadr safe))) + (when risky (put symbol 'risky-local-variable (cadr risky))) + (when set (put symbol 'custom-set (cadr set)))) + ;; This is used by describe-variable. (if version (put symbol 'custom-version version)) ;; `cus-start' can be loaded twice: it's preloaded by `loadup.el' @@ -988,12 +992,14 @@ since it could result in memory overflow and make Emacs crash." ;; Set the type. (put symbol 'custom-type type) (while rest - (setq prop (car rest) - propval (cadr rest) - rest (nthcdr 2 rest)) - (cond ((memq prop '(:standard :risky :safe :set))) ; handled above - ((eq prop :tag) - (put symbol 'custom-tag propval)))))))) + (let ((prop (car rest)) + (propval (cadr rest))) + (setq rest (nthcdr 2 rest)) + (cond ((memq prop '(:standard :risky :safe :set)) + nil) ; handled above + ((eq prop :tag) + (put symbol 'custom-tag propval)) + (t (error "bad keyword in cus-start.el: %S" prop))))))))) (custom-add-to-group 'font-lock 'open-paren-in-column-0-is-defun-start 'custom-variable) commit 6209771ddbc7a3019e89ab22bd2f0b3cbf97e440 Author: Gerd Möllmann Date: Fri Dec 12 17:25:53 2025 +0100 ; Fix xt-mouse-tests * lisp/xt-mouse.el (turn-on-xterm-mouse-tracking-on-terminal): Don't use the terminal's top frame in batch mode. diff --git a/lisp/xt-mouse.el b/lisp/xt-mouse.el index c61dcb0c383..6e19e9c2a09 100644 --- a/lisp/xt-mouse.el +++ b/lisp/xt-mouse.el @@ -517,7 +517,11 @@ enable, ?l to disable)." ;; so that we can set the terminal-local `input-decode-map'. ;; Use the tty-top-frame to avoid accidentally making an invisible ;; child frame visible by selecting it (bug#79960). - (with-selected-frame (tty-top-frame terminal) + ;; The test for match mode is here because xt-mouse-tests run in + ;; match mode, and there is no top-frame in that case. + (with-selected-frame (if noninteractive + (car (frame-list)) + (tty-top-frame terminal)) (define-key input-decode-map "\e[M" 'xterm-mouse-translate) (define-key input-decode-map "\e[<" 'xterm-mouse-translate-extended)) (let ((enable (xterm-mouse-tracking-enable-sequence)) commit 74cbef7c45f2cbff99679ef54656ba369b049f71 Author: Michael Albinus Date: Fri Dec 12 17:01:31 2025 +0100 Fix :type in `antlr-tool-command' * lisp/progmodes/antlr-mode.el (antlr-tool-command): Give it a proper :type. diff --git a/lisp/progmodes/antlr-mode.el b/lisp/progmodes/antlr-mode.el index 15c774a35d6..b31e44c3581 100644 --- a/lisp/progmodes/antlr-mode.el +++ b/lisp/progmodes/antlr-mode.el @@ -751,7 +751,7 @@ This variable should include all options passed to Antlr except the option \"-glib\" which is automatically suggested if necessary. OBSOLETE as user option - customize version dependent user options." - :type 'string) + :type '(choice (const nil) string)) (defcustom antlr-v4-tool-command "java org.antlr.v4.Tool" ;; you probably also need to add s/th like commit 251c070dfde8996189bfb808a0b6f6f5925091b8 Author: Mattias Engdegård Date: Fri Dec 12 13:34:55 2025 +0100 Warn about uses of the 'any' atom in rx 'any' is a holdover from the ancient 'sregex' package where it meant 'not-newline', but is easily mistaken for 'anychar'. * lisp/emacs-lisp/rx.el (rx--translate-symbol): Warn about 'any'. * test/lisp/emacs-lisp/rx-tests.el (rx-atoms): Suppress warning here. * etc/NEWS: Explain. diff --git a/etc/NEWS b/etc/NEWS index 2f362a155bb..27204393f7a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -3428,6 +3428,12 @@ satisfy a given predicate. This means that you can now call it with just one argument, like 'defvar', to declare a variable both special, and buffer-local. +--- +** The rx atom 'any' is obsolete and will cause warning when used. +When used as an atom, 'any' is an old alias for 'not-newline' but is +often mistakenly used where 'anychar' was intended. Note that the +construct '(any ...)' is unrelated and not obsolete. + ** ERT *** Some experimental ERT macros are now considered stable. diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el index 77237b8e5a7..46311b5af02 100644 --- a/lisp/emacs-lisp/rx.el +++ b/lisp/emacs-lisp/rx.el @@ -48,7 +48,7 @@ ;; (not-syntax X) (not (syntax X)) ;; not-wordchar (not wordchar) ;; (not-char ...) (not (any ...)) -;; any nonl, not-newline +;; any nonl, not-newline -- warning since Emacs 31 ;; (repeat N FORM) (= N FORM) ;; (syntax CHARACTER) (syntax NAME) ;; (syntax CHAR-SYM) [1] (syntax NAME) @@ -66,7 +66,7 @@ ;; minimal-match, maximal-match lazy ops: ??, *?, +? ;; FIXME: Prepare a phase-out by emitting compile-time warnings about -;; at least some of the legacy constructs above. +;; more of the legacy constructs above. ;;; Code: @@ -190,7 +190,7 @@ Each entry is: (pcase sym ;; Use `list' instead of a quoted list to wrap the strings here, ;; since the return value may be mutated. - ((or 'nonl 'not-newline 'any) (cons (list ".") t)) + ((or 'nonl 'not-newline) (cons (list ".") t)) ((or 'anychar 'anything) (cons (list "[^z-a]") t)) ('unmatchable (rx--empty)) ((or 'bol 'line-start) (cons (list "^") 'lseq)) @@ -205,6 +205,13 @@ Each entry is: ('symbol-start (cons (list "\\_<") t)) ('symbol-end (cons (list "\\_>") t)) ('not-wordchar (rx--translate '(not wordchar))) + ('any + (when (and (macroexp-compiling-p) + (byte-compile-warning-enabled-p 'obsolete 'any)) + (byte-compile-warn-x + sym (concat "`any' in rx is obsolete and means `not-newline';" + " did you mean `anychar'?"))) + (rx--translate-symbol 'nonl)) (_ (cond ((let ((class (cdr (assq sym rx--char-classes)))) diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el index a485b0f29e1..c60a73b2b58 100644 --- a/test/lisp/emacs-lisp/rx-tests.el +++ b/test/lisp/emacs-lisp/rx-tests.el @@ -296,7 +296,8 @@ "[^z-a][^z-a]")) (should (equal (rx unmatchable) "\\`a\\`")) - (should (equal (rx line-start not-newline nonl any line-end) + (should (equal (with-suppressed-warnings ((obsolete any)) + (rx line-start not-newline nonl any line-end)) "^...$")) (should (equal (rx bol string-start string-end buffer-start buffer-end bos eos bot eot eol) commit 8a58ce0abd5c60a18de3a3cb6e341edab0255ddb Author: Mattias Engdegård Date: Fri Dec 12 13:03:45 2025 +0100 Don't use rx 'any' to mean 'not-newline' * lisp/emacs-lisp/package-vc.el (package-vc--unpack-1): * lisp/pcmpl-rpm.el (pcomplete/dnf): * test/lisp/emacs-lisp/package-vc-tests.el (log-incoming): Use 'anychar' instead of 'any', since that's probably what was meant. diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el index 8338e98d9f0..7cb4bfde51a 100644 --- a/lisp/emacs-lisp/package-vc.el +++ b/lisp/emacs-lisp/package-vc.el @@ -631,7 +631,7 @@ building documentation and marking the package as installed." (dolist (elc-file (directory-files-recursively lisp-dir (rx string-start - (not ".") (zero-or-more any) ".elc" + (not ".") (zero-or-more anychar) ".elc" string-end) nil (lambda (dir) diff --git a/lisp/pcmpl-rpm.el b/lisp/pcmpl-rpm.el index 239500c37dd..d3992f82227 100644 --- a/lisp/pcmpl-rpm.el +++ b/lisp/pcmpl-rpm.el @@ -404,7 +404,7 @@ STATUS should be one of --available or --installed." (while (pcase subcmd ((guard (pcomplete-match "\\`-" 0)) (if-let* (((pcomplete-match (rx bos "--what" (* (not "=")) "=" - (group (* any)) eos) + (group (* anychar)) eos) 0)) (stub (pcomplete-match-string 1 0))) (pcomplete-here (pcmpl-rpm--dnf-packages "--available") stub) diff --git a/test/lisp/emacs-lisp/package-vc-tests.el b/test/lisp/emacs-lisp/package-vc-tests.el index f118a871f99..27faf4acaba 100644 --- a/test/lisp/emacs-lisp/package-vc-tests.el +++ b/test/lisp/emacs-lisp/package-vc-tests.el @@ -989,7 +989,7 @@ car of ARGS (a symbol) to name of the package." (substring (cadr package-vc-tests-repository) 0 7)) - (one-or-more any) + (one-or-more anychar) "Second commit" line-end))) (should (bufferp incoming-buffer)) commit 4bf919a0e605f5a797926e0502312e2770887a49 Author: Mattias Engdegård Date: Fri Dec 12 12:51:08 2025 +0100 ; * lisp/progmodes/antlr-mode.el: useless backslashes diff --git a/lisp/progmodes/antlr-mode.el b/lisp/progmodes/antlr-mode.el index e80789a0d8f..15c774a35d6 100644 --- a/lisp/progmodes/antlr-mode.el +++ b/lisp/progmodes/antlr-mode.el @@ -1144,7 +1144,7 @@ fontification, see `antlr-font-lock-keywords-alist'. While calculating the decoration level for actions, `major-mode' is bound to the value of `antlr-action-mode'. For example, with value - ((java-mode \. 2) (c++-mode \. 0)) + ((java-mode . 2) (c++-mode . 0)) Java actions are fontified with level 2 and C++ actions are not fontified at all." :type '(choice (const :tag "None" none) commit ff2c16689700f0935039113ad0a6f1dede3c0d92 Author: Mattias Engdegård Date: Fri Dec 12 12:38:50 2025 +0100 * doc/lispref/strings.texi (Formatting Strings): Cut obsolete text. Since we got bignums the output is platform-independent. diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi index 7ac73140844..fa629622a71 100644 --- a/doc/lispref/strings.texi +++ b/doc/lispref/strings.texi @@ -1030,8 +1030,7 @@ Functions}). Thus, strings are enclosed in @samp{"} characters, and @item %o @cindex integer to octal Replace the specification with the base-eight representation of an -integer. Negative integers are formatted in a platform-dependent -way. The object can also be a floating-point number that is formatted +integer. The object can also be a floating-point number that is formatted as an integer, dropping any fraction. @item %d @@ -1044,8 +1043,7 @@ formatted as an integer, dropping any fraction. @itemx %X @cindex integer to hexadecimal Replace the specification with the base-sixteen representation of an -integer. Negative integers are formatted in a platform-dependent -way. @samp{%x} uses lower case and @samp{%X} uses upper +integer. @samp{%x} uses lower case and @samp{%X} uses upper case. The object can also be a floating-point number that is formatted as an integer, dropping any fraction. commit ff85f48c2ceef544b22ff4ae28efd9b7cccdafed Author: Mattias Engdegård Date: Fri Dec 12 11:52:38 2025 +0100 * doc/lispref/eval.texi (Backquote): Clarify and simplify. The previous phrasing could be read as if backquote expansion were mutable if containing substitions, but that is simply not true; they should always be treated as non-mutable. diff --git a/doc/lispref/eval.texi b/doc/lispref/eval.texi index 0982145d652..ddf67a09671 100644 --- a/doc/lispref/eval.texi +++ b/doc/lispref/eval.texi @@ -704,8 +704,7 @@ Here are some examples: @end group @end example -If a subexpression of a backquote construct has no substitutions or -splices, it acts like @code{quote} in that it yields conses, +A backquote construct acts like @code{quote} in that it yields conses, vectors and strings that might be shared and should not be modified. @xref{Self-Evaluating Forms}.