aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2023-05-20 14:55:29 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-05-20 18:14:01 +0200
commit9ec31e57278ffc4e680ef03e75ce5b6b02e5edcf (patch)
tree458e020a274453bacf526e444594138ca67c36ef /sysdeps
parent36cc908ed549389713955093bbfeaa35fdaf3e2e (diff)
downloadglibc-9ec31e57278ffc4e680ef03e75ce5b6b02e5edcf.tar.xz
glibc-9ec31e57278ffc4e680ef03e75ce5b6b02e5edcf.zip
hurd: Use __hurd_fail () instead of assigning errno
The __hurd_fail () inline function is the dedicated, idiomatic way of reporting errors in the Hurd part of glibc. Not only is it more concise than '{ errno = err; return -1; }', it is since commit 6639cc10029e24e06b34e169712b21c31b8cf213 "hurd: Mark error functions as __COLD" marked with the cold attribute, telling the compiler that this codepath is unlikely to be executed. In one case, use __hurd_dfail () over the plain __hurd_fail (). Signed-off-by: Sergey Bugaev <bugaevc@gmail.com> Message-Id: <20230520115531.3911877-1-bugaevc@gmail.com>
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/mach/hurd/brk.c7
-rw-r--r--sysdeps/mach/hurd/closedir.c5
-rw-r--r--sysdeps/mach/hurd/cthreads.c12
-rw-r--r--sysdeps/mach/hurd/dirfd.c6
-rw-r--r--sysdeps/mach/hurd/dl-sysdep.c14
-rw-r--r--sysdeps/mach/hurd/dup3.c2
-rw-r--r--sysdeps/mach/hurd/f_setlk.c10
-rw-r--r--sysdeps/mach/hurd/fcntl.c23
-rw-r--r--sysdeps/mach/hurd/fdopendir.c10
-rw-r--r--sysdeps/mach/hurd/getcwd.c10
-rw-r--r--sysdeps/mach/hurd/getegid.c12
-rw-r--r--sysdeps/mach/hurd/getentropy.c15
-rw-r--r--sysdeps/mach/hurd/geteuid.c12
-rw-r--r--sysdeps/mach/hurd/getgid.c12
-rw-r--r--sysdeps/mach/hurd/getlogin.c5
-rw-r--r--sysdeps/mach/hurd/getlogin_r.c7
-rw-r--r--sysdeps/mach/hurd/getrlimit.c5
-rw-r--r--sysdeps/mach/hurd/getuid.c12
-rw-r--r--sysdeps/mach/hurd/i386/sigreturn.c5
-rw-r--r--sysdeps/mach/hurd/if_index.c11
-rw-r--r--sysdeps/mach/hurd/ifreq.c2
-rw-r--r--sysdeps/mach/hurd/libc_sigaction.c5
-rw-r--r--sysdeps/mach/hurd/lseek.c6
-rw-r--r--sysdeps/mach/hurd/mknodat.c5
-rw-r--r--sysdeps/mach/hurd/mmap64.c8
-rw-r--r--sysdeps/mach/hurd/opendir.c23
-rw-r--r--sysdeps/mach/hurd/ptrace.c3
-rw-r--r--sysdeps/mach/hurd/ptsname.c12
-rw-r--r--sysdeps/mach/hurd/readdir.c6
-rw-r--r--sysdeps/mach/hurd/readdir64.c5
-rw-r--r--sysdeps/mach/hurd/readdir64_r.c5
-rw-r--r--sysdeps/mach/hurd/sendmsg.c5
-rw-r--r--sysdeps/mach/hurd/setrlimit.c5
-rw-r--r--sysdeps/mach/hurd/sigaltstack.c3
-rw-r--r--sysdeps/mach/hurd/sigpending.c5
-rw-r--r--sysdeps/mach/hurd/sigprocmask.c3
-rw-r--r--sysdeps/mach/hurd/sigsuspend.c3
-rw-r--r--sysdeps/mach/hurd/spawni.c3
-rw-r--r--sysdeps/mach/hurd/statconv.c6
-rw-r--r--sysdeps/mach/hurd/statfsconv.c6
-rw-r--r--sysdeps/mach/hurd/ttyname_r.c5
-rw-r--r--sysdeps/mach/hurd/unlinkat.c5
-rw-r--r--sysdeps/mach/hurd/waitid.c8
-rw-r--r--sysdeps/mach/hurd/x86_64/sigreturn.c5
44 files changed, 95 insertions, 242 deletions
diff --git a/sysdeps/mach/hurd/brk.c b/sysdeps/mach/hurd/brk.c
index 12aaba5212..f1349495f5 100644
--- a/sysdeps/mach/hurd/brk.c
+++ b/sysdeps/mach/hurd/brk.c
@@ -93,11 +93,8 @@ _hurd_set_brk (vm_address_t addr)
__mutex_unlock (&_hurd_rlimit_lock);
if (addr - brk_start > rlimit)
- {
- /* Need to increase the resource limit. */
- errno = ENOMEM;
- return -1;
- }
+ /* Need to increase the resource limit. */
+ return __hurd_fail (ENOMEM);
if (pagend > _hurd_data_end)
{
diff --git a/sysdeps/mach/hurd/closedir.c b/sysdeps/mach/hurd/closedir.c
index 3a16418f9f..46815f0548 100644
--- a/sysdeps/mach/hurd/closedir.c
+++ b/sysdeps/mach/hurd/closedir.c
@@ -32,10 +32,7 @@ __closedir (DIR *dirp)
error_t err;
if (dirp == NULL)
- {
- errno = EINVAL;
- return -1;
- }
+ return __hurd_fail (EINVAL);
__libc_lock_lock (dirp->__lock);
err = __vm_deallocate (__mach_task_self (),
diff --git a/sysdeps/mach/hurd/cthreads.c b/sysdeps/mach/hurd/cthreads.c
index 87b6c06b67..4f5920bce2 100644
--- a/sysdeps/mach/hurd/cthreads.c
+++ b/sysdeps/mach/hurd/cthreads.c
@@ -17,6 +17,7 @@
#include <libc-lock.h>
#include <errno.h>
+#include <hurd.h>
#include <stdlib.h>
#include <pthreadP.h>
@@ -25,9 +26,8 @@ int
weak_function
__cthread_keycreate (__cthread_key_t *key)
{
- __set_errno (ENOSYS);
- *key = -1;
- return -1;
+ *key = -1;
+ return __hurd_fail (ENOSYS);
}
/* Placeholder for key retrieval routine from Hurd cthreads library. */
@@ -36,8 +36,7 @@ weak_function
__cthread_getspecific (__cthread_key_t key, void **pval)
{
*pval = NULL;
- __set_errno (ENOSYS);
- return -1;
+ return __hurd_fail (ENOSYS);
}
/* Placeholder for key setting routine from Hurd cthreads library. */
@@ -45,6 +44,5 @@ int
weak_function
__cthread_setspecific (__cthread_key_t key, void *val)
{
- __set_errno (ENOSYS);
- return -1;
+ return __hurd_fail (ENOSYS);
}
diff --git a/sysdeps/mach/hurd/dirfd.c b/sysdeps/mach/hurd/dirfd.c
index 9520f3ef89..2cf02c787a 100644
--- a/sysdeps/mach/hurd/dirfd.c
+++ b/sysdeps/mach/hurd/dirfd.c
@@ -18,6 +18,7 @@
#include <dirent.h>
#include <dirstream.h>
+#include <hurd.h>
#include <hurd/fd.h>
#include <errno.h>
@@ -32,10 +33,7 @@ __dirfd (DIR *dirp)
if (_hurd_dtable[fd] == dirp->__fd)
break;
if (fd == _hurd_dtablesize)
- {
- errno = EINVAL;
- fd = -1;
- }
+ fd = __hurd_fail (EINVAL);
__mutex_unlock (&_hurd_dtable_lock);
HURD_CRITICAL_END;
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index 79ebb0ceb1..7c484d76eb 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -285,8 +285,7 @@ open_file (const char *file_name, int flags,
MACH_PORT_RIGHT_SEND, +1);
return _dl_hurd_data->dtable[fd];
}
- errno = EBADF;
- return MACH_PORT_NULL;
+ return __hurd_fail (EBADF), MACH_PORT_NULL;
}
assert (!(flags & ~(O_READ | O_EXEC | O_CLOEXEC | O_IGNORE_CTTY)));
@@ -403,10 +402,7 @@ __ssize_t weak_function
__writev (int fd, const struct iovec *iov, int niov)
{
if (fd >= _hurd_init_dtablesize)
- {
- errno = EBADF;
- return -1;
- }
+ return __hurd_fail (EBADF);
int i;
size_t total = 0;
@@ -554,8 +550,7 @@ check_no_hidden(__access);
int weak_function
__access (const char *file, int type)
{
- errno = ENOSYS;
- return -1;
+ return __hurd_fail (ENOSYS);
}
check_no_hidden(__access_noerrno);
int weak_function
@@ -697,8 +692,7 @@ check_no_hidden(__getcwd);
char *weak_function
__getcwd (char *buf, size_t size)
{
- errno = ENOSYS;
- return NULL;
+ return __hurd_fail (ENOSYS), NULL;
}
/* This is used by dl-tunables.c to strdup strings. We can just make this a
diff --git a/sysdeps/mach/hurd/dup3.c b/sysdeps/mach/hurd/dup3.c
index 0bcbbfd663..c5f64bcecb 100644
--- a/sysdeps/mach/hurd/dup3.c
+++ b/sysdeps/mach/hurd/dup3.c
@@ -103,7 +103,7 @@ __dup3 (int fd, int fd2, int flags)
{
fd2 = -1;
if (errno == EINVAL)
- errno = EBADF; /* POSIX.1-1990 6.2.1.2 ll 54-55. */
+ __hurd_fail (EBADF); /* POSIX.1-1990 6.2.1.2 ll 54-55. */
}
else
{
diff --git a/sysdeps/mach/hurd/f_setlk.c b/sysdeps/mach/hurd/f_setlk.c
index 5c60a6347c..9f1b0baa6c 100644
--- a/sysdeps/mach/hurd/f_setlk.c
+++ b/sysdeps/mach/hurd/f_setlk.c
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <sys/file.h>
#include <fcntl.h>
+#include <hurd.h>
#include <unistd.h>
#include <errno.h>
@@ -39,8 +40,7 @@ __f_setlk (int fd, int type, int whence, __off64_t start, __off64_t len, int wai
case F_WRLCK: cmd = LOCK_EX; break;
case F_UNLCK: cmd = LOCK_UN; break;
default:
- errno = EINVAL;
- return -1;
+ return __hurd_fail (EINVAL);
}
if (cmd != LOCK_UN && wait == 0)
@@ -71,11 +71,9 @@ __f_setlk (int fd, int type, int whence, __off64_t start, __off64_t len, int wai
/* FALLTHROUGH */
case SEEK_CUR:
case SEEK_END:
- errno = ENOTSUP;
- return -1;
+ return __hurd_fail (ENOTSUP);
default:
- errno = EINVAL;
- return -1;
+ return __hurd_fail (EINVAL);
}
return __flock (fd, cmd);
diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c
index a89d6d39df..0b9a64bc57 100644
--- a/sysdeps/mach/hurd/fcntl.c
+++ b/sysdeps/mach/hurd/fcntl.c
@@ -48,8 +48,7 @@ __libc_fcntl (int fd, int cmd, ...)
error_t err;
default: /* Bad command. */
- errno = EINVAL;
- result = -1;
+ result = __hurd_fail (EINVAL);
break;
/* First the descriptor-based commands, which do no RPCs. */
@@ -149,8 +148,7 @@ __libc_fcntl (int fd, int cmd, ...)
cmd = F_SETLKW64;
break;
default:
- errno = EINVAL;
- return -1;
+ return __hurd_fail (EINVAL);
}
struct flock64 fl64 = {
@@ -183,8 +181,7 @@ __libc_fcntl (int fd, int cmd, ...)
switch (cmd)
{
case F_GETLK64:
- errno = ENOSYS;
- return -1;
+ return __hurd_fail (ENOSYS);
case F_SETLKW64:
wait = 1;
/* FALLTHROUGH */
@@ -192,8 +189,7 @@ __libc_fcntl (int fd, int cmd, ...)
return __f_setlk (fd, fl->l_type, fl->l_whence,
fl->l_start, fl->l_len, wait);
default:
- errno = EINVAL;
- return -1;
+ return __hurd_fail (EINVAL);
}
}
else if (cmd == F_GETLK64)
@@ -208,10 +204,7 @@ __libc_fcntl (int fd, int cmd, ...)
&& fl->l_start != fl64.l_start)
|| (sizeof fl->l_len != sizeof fl64.l_len
&& fl->l_len != fl64.l_len))
- {
- errno = EOVERFLOW;
- return -1;
- }
+ return __hurd_fail (EOVERFLOW);
}
result = err ? __hurd_dfail (fd, err) : 0;
@@ -246,8 +239,7 @@ __libc_fcntl (int fd, int cmd, ...)
switch (cmd)
{
case F_GETLK64:
- errno = ENOSYS;
- return -1;
+ return __hurd_fail (ENOSYS);
case F_SETLKW64:
wait = 1;
/* FALLTHROUGH */
@@ -255,8 +247,7 @@ __libc_fcntl (int fd, int cmd, ...)
return __f_setlk (fd, fl->l_type, fl->l_whence,
fl->l_start, fl->l_len, wait);
default:
- errno = EINVAL;
- return -1;
+ return __hurd_fail (EINVAL);
}
}
diff --git a/sysdeps/mach/hurd/fdopendir.c b/sysdeps/mach/hurd/fdopendir.c
index 2a152b07a1..33ea2f0cf2 100644
--- a/sysdeps/mach/hurd/fdopendir.c
+++ b/sysdeps/mach/hurd/fdopendir.c
@@ -31,10 +31,7 @@ __fdopendir (int fd)
struct hurd_fd *d = _hurd_fd_get (fd);
if (d == NULL)
- {
- errno = EBADF;
- return NULL;
- }
+ return __hurd_fail (EBADF), NULL;
/* Ensure that it's a directory. */
error_t err = HURD_FD_PORT_USE
@@ -47,10 +44,7 @@ __fdopendir (int fd)
}));
if (err)
- {
- errno = err;
- return NULL;
- }
+ return __hurd_dfail (fd, err), NULL;
return _hurd_fd_opendir (d);
}
diff --git a/sysdeps/mach/hurd/getcwd.c b/sysdeps/mach/hurd/getcwd.c
index cd3aedd9cd..b9a6f855b0 100644
--- a/sysdeps/mach/hurd/getcwd.c
+++ b/sysdeps/mach/hurd/getcwd.c
@@ -69,10 +69,7 @@ __hurd_canonicalize_directory_name_internal (file_t thisdir,
if (size <= 0)
{
if (buf != NULL)
- {
- errno = EINVAL;
- return NULL;
- }
+ return __hurd_fail (EINVAL), NULL;
size = FILENAME_MAX * 4 + 1; /* Good starting guess. */
}
@@ -227,10 +224,7 @@ __hurd_canonicalize_directory_name_internal (file_t thisdir,
if (offset < d->d_namlen + 1)
{
if (orig_size > 0)
- {
- errno = ERANGE;
- return NULL;
- }
+ return __hurd_fail (ERANGE), NULL;
else
{
size *= 2;
diff --git a/sysdeps/mach/hurd/getegid.c b/sysdeps/mach/hurd/getegid.c
index 7f07d13b1a..9ca56e5729 100644
--- a/sysdeps/mach/hurd/getegid.c
+++ b/sysdeps/mach/hurd/getegid.c
@@ -32,21 +32,15 @@ retry:
__mutex_lock (&_hurd_id.lock);
if (err = _hurd_check_ids ())
- {
- errno = err;
- egid = -1;
- }
+ egid = __hurd_fail (err);
else if (_hurd_id.gen.ngids >= 1)
egid = _hurd_id.gen.gids[0];
else if (_hurd_id.aux.ngids >= 1)
/* We have no effective gids. Return the real gid. */
egid = _hurd_id.aux.gids[0];
else
- {
- /* We do not even have a real gid. */
- errno = EGRATUITOUS;
- egid = -1;
- }
+ /* We do not even have a real gid. */
+ egid = __hurd_fail (EGRATUITOUS);
__mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END;
diff --git a/sysdeps/mach/hurd/getentropy.c b/sysdeps/mach/hurd/getentropy.c
index adbbb78ca0..118f8984e7 100644
--- a/sysdeps/mach/hurd/getentropy.c
+++ b/sysdeps/mach/hurd/getentropy.c
@@ -20,6 +20,7 @@
#include <assert.h>
#include <errno.h>
#include <unistd.h>
+#include <hurd.h>
/* Write LENGTH bytes of randomness starting at BUFFER. Return 0 on
success and -1 on failure. */
@@ -29,10 +30,7 @@ getentropy (void *buffer, size_t length)
/* The interface is documented to return EIO for buffer lengths
longer than 256 bytes. */
if (length > 256)
- {
- __set_errno (EIO);
- return -1;
- }
+ return __hurd_fail (EIO);
/* Try to fill the buffer completely. Even with the 256 byte limit
above, we might still receive an EINTR error (when blocking