Update from Gnulib by running admin/merge-gnulib

This commit is contained in:
Paul Eggert 2025-12-12 15:24:31 -08:00
parent 976143651b
commit 41ffeaec15
61 changed files with 683 additions and 754 deletions

View file

@ -17,10 +17,10 @@
Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible. */
#define ACL_INTERNAL_INLINE _GL_EXTERN_INLINE
#include <config.h>
/* 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))

View file

@ -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

View file

@ -14,9 +14,8 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define BINARY_IO_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include "binary-io.h"
#if defined __DJGPP__ || defined __EMX__

View file

@ -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;
}

View file

@ -15,7 +15,6 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define _GL_BYTESWAP_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include <byteswap.h>

View file

@ -15,7 +15,6 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define C_CTYPE_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include "c-ctype.h"

View file

@ -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);
unsigned char c1 = c_tolower (*p1);
unsigned char c2 = c_tolower (*p2);
if (c1 == '\0')
break;
++p1;
++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);
}

View file

@ -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);
unsigned char c1 = c_tolower (*p1);
unsigned char c2 = c_tolower (*p2);
if (--n == 0 || c1 == '\0')
break;
++p1;
++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);
}

View file

@ -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;

View file

@ -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)

View file

@ -19,5 +19,4 @@
#define _GL_ENDIAN_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include <endian.h>

View file

@ -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);

View file

@ -15,7 +15,6 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define _GL_EXECINFO_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include "execinfo.h"

View file

@ -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;
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;
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_SETFL:
if (arg != 0)
break;
result = 0;
break;
default:
errno = EINVAL;
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;
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_GETFL:
result = 0;
break;
case F_SETFL:
if (arg != 0)
break;
result = 0;
break;
default:
errno = EINVAL;
break;
}
}

View file

@ -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)
{

View file

@ -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);

View file

@ -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. */

View file

@ -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

View file

@ -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:

View file

@ -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 ();

View file

@ -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 */

View file

@ -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;
{
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;
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;
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;
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 >= 2)
{
kn = kstat_data_lookup (ksp, "avenrun_5min");
if (kn != NULL)
{
loadavg[elem++] = (double) kn->value.ul / FSCALE;
if (nelem >= 1)
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;
}
}
}
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)
{

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -92,12 +92,12 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
microseconds.
More discussion on this topic:
<http://www.windowstimestamp.com/description>. */
FILETIME current_time;
# if !(_WIN32_WINNT >= _WIN32_WINNT_WIN8)
if (!initialized)
initialize ();
# endif
FILETIME current_time;
if (GetSystemTimePreciseAsFileTimeFunc != NULL)
GetSystemTimePreciseAsFileTimeFunc (&current_time);
else

View file

@ -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);

View file

@ -14,7 +14,6 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define _GL_ISSYMLINK_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include "issymlink.h"

View file

@ -14,7 +14,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define _GL_ISSYMLINKAT_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include "issymlinkat.h"

View file

@ -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;

View file

@ -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. */
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;
}
}
/* 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.
/* 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.
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;
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);
}
if ((((longword1 - repeated_one) & ~longword1)
& (repeated_one << 7)) != 0)
{
longword_ptr++;
break;
}
n -= sizeof (longword);
}
}
char_ptr = (const unsigned char *) longword_ptr;
{
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;
}
/* 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;
}

View file

@ -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)
{

View file

@ -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;

View file

@ -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/"

View file

@ -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)
{

View file

@ -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)

View file

@ -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;

View file

@ -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;
{
const unsigned char *char_ptr;
longword const *longword_ptr = s = 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;
/* 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);
s = char_ptr;
}
/* 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.
{
longword const *longword_ptr = s;
(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.)
/* 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);
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.
/* 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 test whether any byte in longword1 is zero is equivalent
to testing whether tmp is nonzero.
(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.)
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. */
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.
while (1)
{
longword longword1 = *longword_ptr ^ repeated_c;
The test whether any byte in longword1 is zero is equivalent
to testing whether tmp is nonzero.
if ((((longword1 - repeated_one) & ~longword1) & repeated_hibit) != 0)
break;
longword_ptr++;
}
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. */
char_ptr = s = longword_ptr;
while (1)
{
longword longword1 = *longword_ptr ^ repeated_c;
/* 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. */
if ((((longword1 - repeated_one) & ~longword1) & repeated_hibit) != 0)
break;
longword_ptr++;
}
while (*char_ptr != c)
char_ptr++;
return (void *) char_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
}

View file

@ -20,9 +20,9 @@
/* Ensure that we call the system's realloc() below. */
#define _GL_USE_STDLIB_ALLOC 1
#include <config.h>
#define _GL_REALLOC_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include <stdlib.h>
#include <errno.h>

View file

@ -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)

View file

@ -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] );

View file

@ -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] );

View file

@ -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;

View file

@ -15,7 +15,6 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define _GL_STAT_TIME_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include "stat-time.h"

View file

@ -14,7 +14,6 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define _GL_STDC_BIT_WIDTH_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include <stdbit.h>

View file

@ -14,9 +14,8 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define _GL_STDC_COUNT_ONES_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include <stdbit.h>
#if 1500 <= _MSC_VER && (defined _M_IX86 || defined _M_X64)

View file

@ -14,7 +14,6 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define _GL_STDC_LEADING_ZEROS_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include <stdbit.h>

View file

@ -14,7 +14,6 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define _GL_STDC_TRAILING_ZEROS_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include <stdbit.h>

View file

@ -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)

View file

@ -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;

View file

@ -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, &ltm);
time_t t = mktime_z (tz, &ltm);
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, &ltm);
if (ltm.tm_wday < 0 || ! localtime_rz (0, &lt, &gtm))
time_t lt = mktime_z (tz, &ltm);
if (ltm.tm_wday < 0)
break;
struct tm gtm;
if (! localtime_rz (0, &lt, &gtm))
break;
diff = tm_diff (&ltm, &gtm);
}
@ -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)
{

View file

@ -14,7 +14,6 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define _GL_STRING_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include <string.h>

View file

@ -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)

View file

@ -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);

View file

@ -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

View file

@ -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

View file

@ -15,7 +15,6 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define _GL_TIMESPEC_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include "timespec.h"

View file

@ -15,8 +15,8 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
#define _GL_U64_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include "u64.h"
typedef int dummy;

View file

@ -19,10 +19,10 @@
/* derived from a function in touch.c */
#define _GL_UTIMENS_INLINE _GL_EXTERN_INLINE
#include <config.h>
/* Specification. */
#define _GL_UTIMENS_INLINE _GL_EXTERN_INLINE
#include "utimens.h"
#include <errno.h>
@ -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])
<https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime> */
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 (&current_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;
}

View file

@ -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

View file

@ -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 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2956.htm> and
<https://stackoverflow.com/questions/76847905/>.
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 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2956.htm> and
<https://stackoverflow.com/questions/76847905/>.
ATTENTION! Efforts are underway to change the meaning of this attribute.