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
6639cc1002
"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>
This commit is contained in:
Sergey Bugaev 2023-05-20 14:55:29 +03:00 committed by Samuel Thibault
parent 36cc908ed5
commit 9ec31e5727
49 changed files with 109 additions and 278 deletions

View file

@ -34,10 +34,7 @@ _hurd_alloc_fd (int *fd, int first_fd)
long int rlimit; long int rlimit;
if (first_fd < 0) if (first_fd < 0)
{ return __hurd_fail (EINVAL), NULL;
errno = EINVAL;
return NULL;
}
crit = _hurd_critical_section_lock (); crit = _hurd_critical_section_lock ();
@ -99,7 +96,7 @@ _hurd_alloc_fd (int *fd, int first_fd)
if (size * sizeof (*_hurd_dtable) < size) if (size * sizeof (*_hurd_dtable) < size)
{ {
/* Integer overflow! */ /* Integer overflow! */
errno = ENOMEM; __hurd_fail (ENOMEM);
goto out; goto out;
} }
@ -124,13 +121,13 @@ _hurd_alloc_fd (int *fd, int first_fd)
goto search; goto search;
} }
else else
errno = ENOMEM; __hurd_fail (ENOMEM);
} }
else else
errno = EMFILE; __hurd_fail (EMFILE);
} }
else else
errno = EINVAL; /* Bogus FIRST_FD value. */ __hurd_fail (EINVAL); /* Bogus FIRST_FD value. */
out: out:
__mutex_unlock (&_hurd_dtable_lock); __mutex_unlock (&_hurd_dtable_lock);

View file

@ -126,10 +126,7 @@ __fopenport (mach_port_t port, const char *mode)
/* Check the access mode. */ /* Check the access mode. */
if ((pflags & needflags) != needflags) if ((pflags & needflags) != needflags)
{ return __hurd_fail (EBADF), NULL;
errno = EBADF;
return NULL;
}
return fopencookie ((void *) (uintptr_t) port, return fopencookie ((void *) (uintptr_t) port,
mode, funcsio); mode, funcsio);

View file

@ -35,18 +35,12 @@ __getdport (int fd)
so we don't bother allocating a real table. */ so we don't bother allocating a real table. */
if (_hurd_init_dtable == NULL) if (_hurd_init_dtable == NULL)
{ /* Never had a descriptor table. */
/* Never had a descriptor table. */ return __hurd_fail (EBADF), MACH_PORT_NULL;
errno = EBADF;
return MACH_PORT_NULL;
}
if (fd < 0 || (unsigned int) fd > _hurd_init_dtablesize if (fd < 0 || (unsigned int) fd > _hurd_init_dtablesize
|| _hurd_init_dtable[fd] == MACH_PORT_NULL) || _hurd_init_dtable[fd] == MACH_PORT_NULL)
{ return __hurd_fail (EBADF), MACH_PORT_NULL;
errno = EBADF;
return MACH_PORT_NULL;
}
else else
{ {
__mach_port_mod_refs (__mach_task_self (), _hurd_init_dtable[fd], __mach_port_mod_refs (__mach_task_self (), _hurd_init_dtable[fd],

View file

@ -71,10 +71,7 @@ _hurd_select (int nfds,
struct hurd_sigstate *ss = NULL; struct hurd_sigstate *ss = NULL;
if (nfds < 0 || (pollfds == NULL && nfds > FD_SETSIZE)) if (nfds < 0 || (pollfds == NULL && nfds > FD_SETSIZE))
{ return __hurd_fail (EINVAL);
errno = EINVAL;
return -1;
}
#define IO_SELECT_REPLY_MSGID (21012 + 100) /* XXX */ #define IO_SELECT_REPLY_MSGID (21012 + 100) /* XXX */
#define IO_SELECT_TIMEOUT_REPLY_MSGID (21031 + 100) /* XXX */ #define IO_SELECT_TIMEOUT_REPLY_MSGID (21031 + 100) /* XXX */
@ -86,10 +83,7 @@ _hurd_select (int nfds,
struct timespec now; struct timespec now;
if (timeout->tv_sec < 0 || ! valid_nanoseconds (timeout->tv_nsec)) if (timeout->tv_sec < 0 || ! valid_nanoseconds (timeout->tv_nsec))
{ return __hurd_fail (EINVAL);
errno = EINVAL;
return -1;
}
err = __clock_gettime (CLOCK_REALTIME, &now); err = __clock_gettime (CLOCK_REALTIME, &now);
if (err) if (err)
@ -281,8 +275,7 @@ _hurd_select (int nfds,
{ {
if (sigmask) if (sigmask)
__sigprocmask (SIG_SETMASK, &oset, NULL); __sigprocmask (SIG_SETMASK, &oset, NULL);
errno = EBADF; return __hurd_fail (EBADF);
return -1;
} }
if (nfds > _hurd_dtablesize) if (nfds > _hurd_dtablesize)

View file

@ -48,10 +48,7 @@ _hurd_socket_server (int domain, int dead)
socket_t server; socket_t server;
if (domain < 0) if (domain < 0)
{ return __hurd_fail (EAFNOSUPPORT), MACH_PORT_NULL;
errno = EAFNOSUPPORT;
return MACH_PORT_NULL;
}
retry: retry:
HURD_CRITICAL_BEGIN; HURD_CRITICAL_BEGIN;
@ -99,7 +96,7 @@ retry:
if (server == MACH_PORT_NULL && errno == ENOENT) if (server == MACH_PORT_NULL && errno == ENOENT)
/* If the server node is absent, we don't support that protocol. */ /* If the server node is absent, we don't support that protocol. */
errno = EAFNOSUPPORT; __hurd_fail (EAFNOSUPPORT);
__mutex_unlock (&lock); __mutex_unlock (&lock);
HURD_CRITICAL_END; HURD_CRITICAL_END;

View file

@ -93,11 +93,8 @@ _hurd_set_brk (vm_address_t addr)
__mutex_unlock (&_hurd_rlimit_lock); __mutex_unlock (&_hurd_rlimit_lock);
if (addr - brk_start > rlimit) if (addr - brk_start > rlimit)
{ /* Need to increase the resource limit. */
/* Need to increase the resource limit. */ return __hurd_fail (ENOMEM);
errno = ENOMEM;
return -1;
}
if (pagend > _hurd_data_end) if (pagend > _hurd_data_end)
{ {

View file

@ -32,10 +32,7 @@ __closedir (DIR *dirp)
error_t err; error_t err;
if (dirp == NULL) if (dirp == NULL)
{ return __hurd_fail (EINVAL);
errno = EINVAL;
return -1;
}
__libc_lock_lock (dirp->__lock); __libc_lock_lock (dirp->__lock);
err = __vm_deallocate (__mach_task_self (), err = __vm_deallocate (__mach_task_self (),

View file

@ -17,6 +17,7 @@
#include <libc-lock.h> #include <libc-lock.h>
#include <errno.h> #include <errno.h>
#include <hurd.h>
#include <stdlib.h> #include <stdlib.h>
#include <pthreadP.h> #include <pthreadP.h>
@ -25,9 +26,8 @@ int
weak_function weak_function
__cthread_keycreate (__cthread_key_t *key) __cthread_keycreate (__cthread_key_t *key)
{ {
__set_errno (ENOSYS); *key = -1;
*key = -1; return __hurd_fail (ENOSYS);
return -1;
} }
/* Placeholder for key retrieval routine from Hurd cthreads library. */ /* Placeholder for key retrieval routine from Hurd cthreads library. */
@ -36,8 +36,7 @@ weak_function
__cthread_getspecific (__cthread_key_t key, void **pval) __cthread_getspecific (__cthread_key_t key, void **pval)
{ {
*pval = NULL; *pval = NULL;
__set_errno (ENOSYS); return __hurd_fail (ENOSYS);
return -1;
} }
/* Placeholder for key setting routine from Hurd cthreads library. */ /* Placeholder for key setting routine from Hurd cthreads library. */
@ -45,6 +44,5 @@ int
weak_function weak_function
__cthread_setspecific (__cthread_key_t key, void *val) __cthread_setspecific (__cthread_key_t key, void *val)
{ {
__set_errno (ENOSYS); return __hurd_fail (ENOSYS);
return -1;
} }

View file

@ -18,6 +18,7 @@
#include <dirent.h> #include <dirent.h>
#include <dirstream.h> #include <dirstream.h>
#include <hurd.h>
#include <hurd/fd.h> #include <hurd/fd.h>
#include <errno.h> #include <errno.h>
@ -32,10 +33,7 @@ __dirfd (DIR *dirp)
if (_hurd_dtable[fd] == dirp->__fd) if (_hurd_dtable[fd] == dirp->__fd)
break; break;
if (fd == _hurd_dtablesize) if (fd == _hurd_dtablesize)
{ fd = __hurd_fail (EINVAL);
errno = EINVAL;
fd = -1;
}
__mutex_unlock (&_hurd_dtable_lock); __mutex_unlock (&_hurd_dtable_lock);
HURD_CRITICAL_END; HURD_CRITICAL_END;

View file

@ -285,8 +285,7 @@ open_file (const char *file_name, int flags,
MACH_PORT_RIGHT_SEND, +1); MACH_PORT_RIGHT_SEND, +1);
return _dl_hurd_data->dtable[fd]; return _dl_hurd_data->dtable[fd];
} }
errno = EBADF; return __hurd_fail (EBADF), MACH_PORT_NULL;
return MACH_PORT_NULL;
} }
assert (!(flags & ~(O_READ | O_EXEC | O_CLOEXEC | O_IGNORE_CTTY))); 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) __writev (int fd, const struct iovec *iov, int niov)
{ {
if (fd >= _hurd_init_dtablesize) if (fd >= _hurd_init_dtablesize)
{ return __hurd_fail (EBADF);
errno = EBADF;
return -1;
}
int i; int i;
size_t total = 0; size_t total = 0;
@ -554,8 +550,7 @@ check_no_hidden(__access);
int weak_function int weak_function
__access (const char *file, int type) __access (const char *file, int type)
{ {
errno = ENOSYS; return __hurd_fail (ENOSYS);
return -1;
} }
check_no_hidden(__access_noerrno); check_no_hidden(__access_noerrno);
int weak_function int weak_function
@ -697,8 +692,7 @@ check_no_hidden(__getcwd);
char *weak_function char *weak_function
__getcwd (char *buf, size_t size) __getcwd (char *buf, size_t size)
{ {
errno = ENOSYS; return __hurd_fail (ENOSYS), NULL;
return NULL;
} }
/* This is used by dl-tunables.c to strdup strings. We can just make this a /* This is used by dl-tunables.c to strdup strings. We can just make this a

View file

@ -103,7 +103,7 @@ __dup3 (int fd, int fd2, int flags)
{ {
fd2 = -1; fd2 = -1;
if (errno == EINVAL) 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 else
{ {

View file

@ -19,6 +19,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/file.h> #include <sys/file.h>
#include <fcntl.h> #include <fcntl.h>
#include <hurd.h>
#include <unistd.h> #include <unistd.h>
#include <errno.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_WRLCK: cmd = LOCK_EX; break;
case F_UNLCK: cmd = LOCK_UN; break; case F_UNLCK: cmd = LOCK_UN; break;
default: default:
errno = EINVAL; return __hurd_fail (EINVAL);
return -1;
} }
if (cmd != LOCK_UN && wait == 0) 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 */ /* FALLTHROUGH */
case SEEK_CUR: case SEEK_CUR:
case SEEK_END: case SEEK_END:
errno = ENOTSUP; return __hurd_fail (ENOTSUP);
return -1;
default: default:
errno = EINVAL; return __hurd_fail (EINVAL);
return -1;
} }
return __flock (fd, cmd); return __flock (fd, cmd);

View file

@ -48,8 +48,7 @@ __libc_fcntl (int fd, int cmd, ...)
error_t err; error_t err;
default: /* Bad command. */ default: /* Bad command. */
errno = EINVAL; result = __hurd_fail (EINVAL);
result = -1;
break; break;
/* First the descriptor-based commands, which do no RPCs. */ /* First the descriptor-based commands, which do no RPCs. */
@ -149,8 +148,7 @@ __libc_fcntl (int fd, int cmd, ...)
cmd = F_SETLKW64; cmd = F_SETLKW64;
break; break;
default: default:
errno = EINVAL; return __hurd_fail (EINVAL);
return -1;
} }
struct flock64 fl64 = { struct flock64 fl64 = {
@ -183,8 +181,7 @@ __libc_fcntl (int fd, int cmd, ...)
switch (cmd) switch (cmd)
{ {
case F_GETLK64: case F_GETLK64:
errno = ENOSYS; return __hurd_fail (ENOSYS);
return -1;
case F_SETLKW64: case F_SETLKW64:
wait = 1; wait = 1;
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -192,8 +189,7 @@ __libc_fcntl (int fd, int cmd, ...)
return __f_setlk (fd, fl->l_type, fl->l_whence, return __f_setlk (fd, fl->l_type, fl->l_whence,
fl->l_start, fl->l_len, wait); fl->l_start, fl->l_len, wait);
default: default:
errno = EINVAL; return __hurd_fail (EINVAL);
return -1;
} }
} }
else if (cmd == F_GETLK64) else if (cmd == F_GETLK64)
@ -208,10 +204,7 @@ __libc_fcntl (int fd, int cmd, ...)
&& fl->l_start != fl64.l_start) && fl->l_start != fl64.l_start)
|| (sizeof fl->l_len != sizeof fl64.l_len || (sizeof fl->l_len != sizeof fl64.l_len
&& fl->l_len != fl64.l_len)) && fl->l_len != fl64.l_len))
{ return __hurd_fail (EOVERFLOW);
errno = EOVERFLOW;
return -1;
}
} }
result = err ? __hurd_dfail (fd, err) : 0; result = err ? __hurd_dfail (fd, err) : 0;
@ -246,8 +239,7 @@ __libc_fcntl (int fd, int cmd, ...)
switch (cmd) switch (cmd)
{ {
case F_GETLK64: case F_GETLK64:
errno = ENOSYS; return __hurd_fail (ENOSYS);
return -1;
case F_SETLKW64: case F_SETLKW64:
wait = 1; wait = 1;
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -255,8 +247,7 @@ __libc_fcntl (int fd, int cmd, ...)
return __f_setlk (fd, fl->l_type, fl->l_whence, return __f_setlk (fd, fl->l_type, fl->l_whence,
fl->l_start, fl->l_len, wait); fl->l_start, fl->l_len, wait);
default: default:
errno = EINVAL; return __hurd_fail (EINVAL);
return -1;
} }
} }

View file

@ -31,10 +31,7 @@ __fdopendir (int fd)
struct hurd_fd *d = _hurd_fd_get (fd); struct hurd_fd *d = _hurd_fd_get (fd);
if (d == NULL) if (d == NULL)
{ return __hurd_fail (EBADF), NULL;
errno = EBADF;
return NULL;
}
/* Ensure that it's a directory. */ /* Ensure that it's a directory. */
error_t err = HURD_FD_PORT_USE error_t err = HURD_FD_PORT_USE
@ -47,10 +44,7 @@ __fdopendir (int fd)
})); }));
if (err) if (err)
{ return __hurd_dfail (fd, err), NULL;
errno = err;
return NULL;
}
return _hurd_fd_opendir (d); return _hurd_fd_opendir (d);
} }

View file

@ -69,10 +69,7 @@ __hurd_canonicalize_directory_name_internal (file_t thisdir,
if (size <= 0) if (size <= 0)
{ {
if (buf != NULL) if (buf != NULL)
{ return __hurd_fail (EINVAL), NULL;
errno = EINVAL;
return NULL;
}
size = FILENAME_MAX * 4 + 1; /* Good starting guess. */ 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 (offset < d->d_namlen + 1)
{ {
if (orig_size > 0) if (orig_size > 0)
{ return __hurd_fail (ERANGE), NULL;
errno = ERANGE;
return NULL;
}
else else
{ {
size *= 2; size *= 2;

View file

@ -32,21 +32,15 @@ retry:
__mutex_lock (&_hurd_id.lock); __mutex_lock (&_hurd_id.lock);
if (err = _hurd_check_ids ()) if (err = _hurd_check_ids ())
{ egid = __hurd_fail (err);
errno = err;
egid = -1;
}
else if (_hurd_id.gen.ngids >= 1) else if (_hurd_id.gen.ngids >= 1)
egid = _hurd_id.gen.gids[0]; egid = _hurd_id.gen.gids[0];
else if (_hurd_id.aux.ngids >= 1) else if (_hurd_id.aux.ngids >= 1)
/* We have no effective gids. Return the real gid. */ /* We have no effective gids. Return the real gid. */
egid = _hurd_id.aux.gids[0]; egid = _hurd_id.aux.gids[0];
else else
{ /* We do not even have a real gid. */
/* We do not even have a real gid. */ egid = __hurd_fail (EGRATUITOUS);
errno = EGRATUITOUS;
egid = -1;
}
__mutex_unlock (&_hurd_id.lock); __mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END; HURD_CRITICAL_END;

View file

@ -20,6 +20,7 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <hurd.h>
/* Write LENGTH bytes of randomness starting at BUFFER. Return 0 on /* Write LENGTH bytes of randomness starting at BUFFER. Return 0 on
success and -1 on failure. */ 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 /* The interface is documented to return EIO for buffer lengths
longer than 256 bytes. */ longer than 256 bytes. */
if (length > 256) if (length > 256)
{ return __hurd_fail (EIO);
__set_errno (EIO);
return -1;
}
/* Try to fill the buffer completely. Even with the 256 byte limit /* Try to fill the buffer completely. Even with the 256 byte limit
above, we might still receive an EINTR error (when blocking above, we might still receive an EINTR error (when blocking
@ -51,12 +49,9 @@ getentropy (void *buffer, size_t length)
return -1; return -1;
} }
if (bytes == 0) if (bytes == 0)
{ /* No more bytes available. This should not happen under
/* No more bytes available. This should not happen under normal circumstances. */
normal circumstances. */ return __hurd_fail (EIO);
__set_errno (EIO);
return -1;
}
/* Try again in case of a short read. */ /* Try again in case of a short read. */
buffer += bytes; buffer += bytes;
} }

View file

@ -32,21 +32,15 @@ retry:
__mutex_lock (&_hurd_id.lock); __mutex_lock (&_hurd_id.lock);
if (err = _hurd_check_ids ()) if (err = _hurd_check_ids ())
{ euid = __hurd_fail (err);
errno = err;
euid = -1;
}
else if (_hurd_id.gen.nuids >= 1) else if (_hurd_id.gen.nuids >= 1)
euid = _hurd_id.gen.uids[0]; euid = _hurd_id.gen.uids[0];
else if (_hurd_id.aux.nuids >= 1) else if (_hurd_id.aux.nuids >= 1)
/* We have no effective uids. Return the real uid. */ /* We have no effective uids. Return the real uid. */
euid = _hurd_id.aux.uids[0]; euid = _hurd_id.aux.uids[0];
else else
{ /* We do not even have a real uid. */
/* We do not even have a real uid. */ euid = __hurd_fail (EGRATUITOUS);
errno = EGRATUITOUS;
euid = -1;
}
__mutex_unlock (&_hurd_id.lock); __mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END; HURD_CRITICAL_END;

View file

@ -32,18 +32,12 @@ retry:
__mutex_lock (&_hurd_id.lock); __mutex_lock (&_hurd_id.lock);
if (err = _hurd_check_ids ()) if (err = _hurd_check_ids ())
{ gid = __hurd_fail (err);
errno = err;
gid = -1;
}
else if (_hurd_id.aux.ngids >= 1) else if (_hurd_id.aux.ngids >= 1)
gid = _hurd_id.aux.gids[0]; gid = _hurd_id.aux.gids[0];
else else
{ /* We do not even have a real gid. */
/* We do not even have a real gid. */ gid = __hurd_fail (EGRATUITOUS);
errno = EGRATUITOUS;
gid = -1;
}
__mutex_unlock (&_hurd_id.lock); __mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END; HURD_CRITICAL_END;

View file

@ -29,10 +29,7 @@ getlogin (void)
error_t err; error_t err;
if (err = __USEPORT (PROC, __proc_getlogin (port, login))) if (err = __USEPORT (PROC, __proc_getlogin (port, login)))
{ return __hurd_fail (err), NULL;
errno = err;
return NULL;
}
return login; return login;
} }

View file

@ -31,14 +31,11 @@ __getlogin_r (char *name, size_t name_len)
error_t err; error_t err;
if (err = __USEPORT (PROC, __proc_getlogin (port, login))) if (err = __USEPORT (PROC, __proc_getlogin (port, login)))
return errno = err; return __hurd_fail (err), err;
size_t len = __strnlen (login, sizeof login - 1) + 1; size_t len = __strnlen (login, sizeof login - 1) + 1;
if (len > name_len) if (len > name_len)
{ return __hurd_fail (ERANGE), ERANGE;
errno = ERANGE;
return errno;
}
memcpy (name, login, len); memcpy (name, login, len);
return 0; return 0;

View file

@ -28,10 +28,7 @@ __getrlimit (enum __rlimit_resource resource, struct rlimit *rlimits)
struct rlimit lim; struct rlimit lim;
if (rlimits == NULL || (unsigned int) resource >= RLIMIT_NLIMITS) if (rlimits == NULL || (unsigned int) resource >= RLIMIT_NLIMITS)
{ return __hurd_fail (EINVAL);
errno = EINVAL;
return -1;
}
HURD_CRITICAL_BEGIN; HURD_CRITICAL_BEGIN;
__mutex_lock (&_hurd_rlimit_lock); __mutex_lock (&_hurd_rlimit_lock);

View file

@ -32,18 +32,12 @@ retry:
__mutex_lock (&_hurd_id.lock); __mutex_lock (&_hurd_id.lock);
if (err = _hurd_check_ids ()) if (err = _hurd_check_ids ())
{ uid = __hurd_fail (err);
errno = err;
uid = -1;
}
else if (_hurd_id.aux.nuids >= 1) else if (_hurd_id.aux.nuids >= 1)
uid = _hurd_id.aux.uids[0]; uid = _hurd_id.aux.uids[0];
else else
{ /* We do not even have a real uid. */
/* We do not even have a real uid. */ uid = __hurd_fail (EGRATUITOUS);
errno = EGRATUITOUS;
uid = -1;
}
__mutex_unlock (&_hurd_id.lock); __mutex_unlock (&_hurd_id.lock);
HURD_CRITICAL_END; HURD_CRITICAL_END;

View file

@ -84,10 +84,7 @@ __sigreturn (struct sigcontext *scp)
struct hurd_userlink *link = (void *) &scp[1]; struct hurd_userlink *link = (void *) &scp[1];
if (__glibc_unlikely (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK))) if (__glibc_unlikely (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK)))
{ return __hurd_fail (EINVAL);
errno = EINVAL;
return -1;
}
ss = _hurd_self_sigstate (); ss = _hurd_self_sigstate ();
_hurd_sigstate_lock (ss); _hurd_sigstate_lock (ss);

View file

@ -38,10 +38,7 @@ __if_nametoindex (const char *ifname)
return 0; return 0;
if (strlen (ifname) >= IFNAMSIZ) if (strlen (ifname) >= IFNAMSIZ)
{ return __hurd_fail (ENODEV), 0;
__set_errno (ENODEV);
return 0;
}
strncpy (ifr.ifr_name, ifname, IFNAMSIZ); strncpy (ifr.ifr_name, ifname, IFNAMSIZ);
if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0) if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0)
@ -49,7 +46,7 @@ __if_nametoindex (const char *ifname)
int saved_errno = errno; int saved_errno = errno;
__close (fd); __close (fd);
if (saved_errno == EINVAL || saved_errno == ENOTTY) if (saved_errno == EINVAL || saved_errno == ENOTTY)
__set_errno (ENOSYS); __hurd_fail (ENOSYS);
return 0; return 0;
} }
__close (fd); __close (fd);
@ -180,9 +177,9 @@ __if_indextoname (unsigned int ifindex, char ifname[IF_NAMESIZE])
int saved_errno = errno; int saved_errno = errno;
__close (fd); __close (fd);
if (saved_errno == EINVAL || saved_errno == ENOTTY) if (saved_errno == EINVAL || saved_errno == ENOTTY)
__set_errno (ENOSYS); __hurd_fail (ENOSYS);
else if (saved_errno == ENODEV) else if (saved_errno == ENODEV)
__set_errno (ENXIO); __hurd_fail (ENXIO);
return NULL; return NULL;
} }
__close (fd); __close (fd);

View file

@ -54,7 +54,7 @@ __ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd)
if (len % sizeof (struct ifreq) != 0) if (len % sizeof (struct ifreq) != 0)
{ {
__munmap (data, len); __munmap (data, len);
errno = EGRATUITOUS; __hurd_fail (EGRATUITOUS);
goto out; goto out;
} }
*num_ifs = len / sizeof (struct ifreq); *num_ifs = len / sizeof (struct ifreq);

View file

@ -33,10 +33,7 @@ __libc_sigaction (int sig, const struct sigaction *act,
if (act != NULL && act->sa_handler != SIG_DFL if (act != NULL && act->sa_handler != SIG_DFL
&& ((__sigmask (sig) & _SIG_CANT_MASK) || act->sa_handler == SIG_ERR)) && ((__sigmask (sig) & _SIG_CANT_MASK) || act->sa_handler == SIG_ERR))
{ return __hurd_fail (EINVAL);
errno = EINVAL;
return -1;
}
/* Copy so we fault before taking locks. */ /* Copy so we fault before taking locks. */
if (act != NULL) if (act != NULL)

View file

@ -18,6 +18,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <errno.h> #include <errno.h>
#include <hurd.h>
/* Seek to OFFSET on FD, starting from WHENCE. */ /* Seek to OFFSET on FD, starting from WHENCE. */
off_t off_t
@ -27,10 +28,7 @@ __libc_lseek (int fd, off_t offset, int whence)
off_t res = (off_t) res64; off_t res = (off_t) res64;
if (sizeof res != sizeof res64 && res != res64) if (sizeof res != sizeof res64 && res != res64)
{ return (off_t) __hurd_fail (EOVERFLOW);
__set_errno (EOVERFLOW);
return (off_t) -1;
}
return res; return res;
} }

View file

@ -63,10 +63,7 @@ __mknodat (int fd, const char *path, mode_t mode, dev_t dev)
len = 0; len = 0;
} }
else else
{ return __hurd_fail (EINVAL);
errno = EINVAL;
return -1;
}
if (translator != NULL && ! S_ISFIFO (mode)) if (translator != NULL && ! S_ISFIFO (mode))
{ {

View file

@ -19,6 +19,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/types.h> #include <sys/types.h>
#include <mach/port.h> #include <mach/port.h>
#include <hurd.h>
/* Map addresses starting near ADDR and extending for LEN bytes. From /* Map addresses starting near ADDR and extending for LEN bytes. From
OFFSET into the file FD describes according to PROT and FLAGS. If ADDR OFFSET into the file FD describes according to PROT and FLAGS. If ADDR
@ -36,11 +37,8 @@ __mmap64 (void *addr, size_t len, int prot, int flags, int fd,
vm_offset_t small_offset = (vm_offset_t) offset; vm_offset_t small_offset = (vm_offset_t) offset;
if (small_offset != offset) if (small_offset != offset)
{ /* We cannot do this since the offset is too large. */
/* We cannot do this since the offset is too large. */ return __hurd_fail (EOVERFLOW), MAP_FAILED;
__set_errno (EOVERFLOW);
return MAP_FAILED;
}
return __mmap (addr, len, prot, flags, fd, small_offset); return __mmap (addr, len, prot, flags, fd, small_offset);
} }

View file

@ -40,10 +40,7 @@ _hurd_fd_opendir (struct hurd_fd *d)
DIR *dirp; DIR *dirp;
if (d == NULL) if (d == NULL)
{ return __hurd_fail (EBADF), NULL;
errno = EBADF;
return NULL;
}
dirp = (DIR *) malloc (sizeof (DIR)); dirp = (DIR *) malloc (sizeof (DIR));
if (dirp == NULL) if (dirp == NULL)
@ -72,12 +69,9 @@ DIR *
__opendirat (int dfd, const char *name) __opendirat (int dfd, const char *name)
{ {
if (name[0] == '\0') if (name[0] == '\0')
{ /* POSIX.1-1990 says an empty name gets ENOENT;
/* POSIX.1-1990 says an empty name gets ENOENT; but `open' might like it fine. */
but `open' might like it fine. */ return __hurd_fail (ENOENT), NULL;
__set_errno (ENOENT);
return NULL;
}
int flags = O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC; int flags = O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC;
int fd; int fd;
@ -107,12 +101,9 @@ __opendir (const char *name)
return __opendirat (AT_FDCWD, name); return __opendirat (AT_FDCWD, name);
#else #else
if (name[0] == '\0') if (name[0] == '\0')
{ /* POSIX.1-1990 says an empty name gets ENOENT;
/* POSIX.1-1990 says an empty name gets ENOENT; but `open' might like it fine. */
but `open' might like it fine. */ return __hurd_fail (ENOENT), NULL;
__set_errno (ENOENT);
return NULL;
}
int fd = __open (name, O_RDONLY | O_NONBLOCK | O_DIRECTORY); int fd = __open (name, O_RDONLY | O_NONBLOCK | O_DIRECTORY);
if (fd < 0) if (fd < 0)

View file

@ -380,8 +380,7 @@ ptrace (enum __ptrace_request request, ... )
} }
default: default:
errno = EINVAL; return __hurd_fail (EINVAL);
return -1;
} }
return 0; return 0;

View file

@ -49,11 +49,8 @@ __ptsname_internal (int fd, char *buf, size_t buflen, struct stat64 *stp)
int ttype; int ttype;
if (HURD_DPORT_USE (fd, __term_get_bottom_type (port, &ttype)) == 0) if (HURD_DPORT_USE (fd, __term_get_bottom_type (port, &ttype)) == 0)
{ /* get_bottom_type suceeded, this is the slave side. */
/* get_bottom_type suceeded, this is the slave side. */ return __hurd_fail (ENOTTY), ENOTTY;
errno = ENOTTY;
return ENOTTY;
}
if (err = HURD_DPORT_USE (fd, __term_get_peername (port, peername))) if (err = HURD_DPORT_USE (fd, __term_get_peername (port, peername)))
{ {
@ -64,10 +61,7 @@ __ptsname_internal (int fd, char *buf, size_t buflen, struct stat64 *stp)
len = __strnlen (peername, sizeof peername - 1) + 1; len = __strnlen (peername, sizeof peername - 1) + 1;
if (len > buflen) if (len > buflen)
{ return __hurd_fail (ERANGE), ERANGE;
errno = ERANGE;
return ERANGE;
}
if (stp) if (stp)
{ {

View file

@ -21,6 +21,7 @@
#include <unistd.h> #include <unistd.h>
#include <endian.h> #include <endian.h>
#include <assert.h> #include <assert.h>
#include <hurd.h>
/* Read a directory entry from DIRP. */ /* Read a directory entry from DIRP. */
struct dirent * struct dirent *
@ -52,10 +53,7 @@ __readdir (DIR *dirp)
- sizeof entry->d_ino); - sizeof entry->d_ino);
const ino_t d_ino = entry64->d_ino; const ino_t d_ino = entry64->d_ino;
if (d_ino != entry64->d_ino) if (d_ino != entry64->d_ino)
{ return __hurd_fail (EOVERFLOW), NULL;
__set_errno (EOVERFLOW);
return NULL;
}
# if BYTE_ORDER != BIG_ENDIAN /* We just skipped over the zero high word. */ # if BYTE_ORDER != BIG_ENDIAN /* We just skipped over the zero high word. */
entry->d_ino = d_ino; /* ... or the nonzero low word, swap it. */ entry->d_ino = d_ino; /* ... or the nonzero low word, swap it. */
# endif # endif

View file

@ -29,10 +29,7 @@ __readdir64 (DIR *dirp)
struct dirent64 *dp; struct dirent64 *dp;
if (dirp == NULL) if (dirp == NULL)
{ return __hurd_fail (EINVAL), NULL;
errno = EINVAL;
return NULL;
}
__libc_lock_lock (dirp->__lock); __libc_lock_lock (dirp->__lock);

View file

@ -31,10 +31,7 @@ __readdir64_r (DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
error_t err = 0; error_t err = 0;
if (dirp == NULL) if (dirp == NULL)
{ return __hurd_fail (EINVAL), EINVAL;
errno = EINVAL;
return errno;
}
__libc_lock_lock (dirp->__lock); __libc_lock_lock (dirp->__lock);

View file

@ -82,10 +82,7 @@ __libc_sendmsg (int fd, const struct msghdr *message, int flags)
{ {
err = __vm_allocate (__mach_task_self (), &data.addr, len, 1); err = __vm_allocate (__mach_task_self (), &data.addr, len, 1);
if (err) if (err)
{ return __hurd_fail (err);
__set_errno (err);
return -1;
}
dealloc = 1; dealloc = 1;
} }
else else

View file

@ -30,10 +30,7 @@ __setrlimit (enum __rlimit_resource resource, const struct rlimit *rlimits)
struct rlimit lim; struct rlimit lim;
if (rlimits == NULL || (unsigned int) resource >= RLIMIT_NLIMITS) if (rlimits == NULL || (unsigned int) resource >= RLIMIT_NLIMITS)
{ return __hurd_fail (EINVAL);
errno = EINVAL;
return -1;
}
lim = *rlimits; lim = *rlimits;

View file

@ -42,8 +42,7 @@ __sigaltstack (const stack_t *argss, stack_t *oss)
{ {
/* Can't disable a stack that is in use. */ /* Can't disable a stack that is in use. */
__spin_unlock (&s->lock); __spin_unlock (&s->lock);
errno = EINVAL; return __hurd_fail (EINVAL);
return -1;
} }
old = s->sigaltstack; old = s->sigaltstack;

View file

@ -30,10 +30,7 @@ sigpending (sigset_t *set)
sigset_t pending; sigset_t pending;
if (set == NULL) if (set == NULL)
{ return __hurd_fail (EINVAL);
errno = EINVAL;
return -1;
}
ss = _hurd_self_sigstate (); ss = _hurd_self_sigstate ();
_hurd_sigstate_lock (ss); _hurd_sigstate_lock (ss);

View file

@ -58,8 +58,7 @@ __sigprocmask (int how, const sigset_t *set, sigset_t *oset)
default: default:
_hurd_sigstate_unlock (ss); _hurd_sigstate_unlock (ss);
errno = EINVAL; return __hurd_fail (EINVAL);
return -1;
} }
ss->blocked &= ~_SIG_CANT_MASK; ss->blocked &= ~_SIG_CANT_MASK;

View file

@ -81,8 +81,7 @@ __sigsuspend (const sigset_t *set)
/* We've been interrupted! And a good thing, too. /* We've been interrupted! And a good thing, too.
Otherwise we'd never return. Otherwise we'd never return.
That's right; this function always returns an error. */ That's right; this function always returns an error. */
errno = EINTR; return __hurd_fail (EINTR);
return -1;
} }
libc_hidden_def (__sigsuspend) libc_hidden_def (__sigsuspend)
weak_alias (__sigsuspend, sigsuspend) weak_alias (__sigsuspend, sigsuspend)

View file

@ -216,8 +216,7 @@ __spawni (pid_t *pid, const char *file,
MACH_PORT_RIGHT_SEND, +1); MACH_PORT_RIGHT_SEND, +1);
return dtable[fd]; return dtable[fd];
} }
errno = EBADF; return __hurd_fail (EBADF), MACH_PORT_NULL;
return MACH_PORT_NULL;
} }
inline error_t child_lookup (const char *file, int oflag, mode_t mode, inline error_t child_lookup (const char *file, int oflag, mode_t mode,
file_t *result) file_t *result)

View file

@ -18,6 +18,7 @@
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <hurd.h>
static inline int static inline int
stat64_conv (struct stat *buf, const struct stat64 *buf64) stat64_conv (struct stat *buf, const struct stat64 *buf64)
@ -55,10 +56,7 @@ stat64_conv (struct stat *buf, const struct stat64 *buf64)
&& buf->st_size != buf64->st_size) && buf->st_size != buf64->st_size)
|| (sizeof buf->st_blocks != sizeof buf64->st_blocks || (sizeof buf->st_blocks != sizeof buf64->st_blocks
&& buf->st_blocks != buf64->st_blocks)) && buf->st_blocks != buf64->st_blocks))
{ return __hurd_fail (EOVERFLOW);
__set_errno (EOVERFLOW);
return -1;
}
return 0; return 0;
} }

View file

@ -18,6 +18,7 @@
#include <sys/statfs.h> #include <sys/statfs.h>
#include <errno.h> #include <errno.h>
#include <hurd.h>
static inline int static inline int
statfs64_conv (struct statfs *buf, const struct statfs64 *buf64) statfs64_conv (struct statfs *buf, const struct statfs64 *buf64)
@ -25,10 +26,7 @@ statfs64_conv (struct statfs *buf, const struct statfs64 *buf64)
# define DO(memb) \ # define DO(memb) \
buf->memb = buf64->memb; \ buf->memb = buf64->memb; \
if (sizeof buf->memb != sizeof buf64->memb && buf->memb != buf64->memb) \ if (sizeof buf->memb != sizeof buf64->memb && buf->memb != buf64->memb) \
{ \ return __hurd_fail (EOVERFLOW);
__set_errno (EOVERFLOW); \
return -1; \
}
DO (f_type); DO (f_type);
DO (f_bsize); DO (f_bsize);

View file

@ -41,10 +41,7 @@ __ttyname_r (int fd, char *buf, size_t buflen)
len = strlen (nodename) + 1; len = strlen (nodename) + 1;
if (len > buflen) if (len > buflen)
{ return __hurd_fail (ERANGE), ERANGE;
errno = ERANGE;
return errno;
}
memcpy (buf, nodename, len); memcpy (buf, nodename, len);
return 0; return 0;

View file

@ -33,10 +33,7 @@ __unlinkat (int fd, const char *name, int flag)
const char *file; const char *file;
if ((flag &~ AT_REMOVEDIR) != 0) if ((flag &~ AT_REMOVEDIR) != 0)
{ return __hurd_fail (EINVAL);
__set_errno (EINVAL);
return -1;
}
dir = __directory_name_split_at (fd, name, (char **) &file); dir = __directory_name_split_at (fd, name, (char **) &file);
if (dir == MACH_PORT_NULL) if (dir == MACH_PORT_NULL)

View file

@ -52,8 +52,7 @@ __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
break; break;
default: default:
invalid: invalid:
__set_errno (EINVAL); return __hurd_fail (EINVAL);
return -1;
} }
/* Technically we're supposed to return EFAULT if infop is bogus, /* Technically we're supposed to return EFAULT if infop is bogus,
@ -62,10 +61,7 @@ __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
We just check for a null pointer. */ We just check for a null pointer. */
if (infop == NULL) if (infop == NULL)
{ return __hurd_fail (EFAULT);
__set_errno (EFAULT);
return -1;
}
cancel_oldtype = LIBC_CANCEL_ASYNC(); cancel_oldtype = LIBC_CANCEL_ASYNC();
#if HURD_INTERFACE_VERSION >= 20201227 #if HURD_INTERFACE_VERSION >= 20201227

View file

@ -79,10 +79,7 @@ __sigreturn (struct sigcontext *scp)
struct hurd_userlink *link = (void *) &scp[1]; struct hurd_userlink *link = (void *) &scp[1];
if (__glibc_unlikely (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK))) if (__glibc_unlikely (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK)))
{ return __hurd_fail (EINVAL);
errno = EINVAL;
return -1;
}
ss = _hurd_self_sigstate (); ss = _hurd_self_sigstate ();
_hurd_sigstate_lock (ss); _hurd_sigstate_lock (ss);