]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: Use __hurd_fail () instead of assigning errno
authorSergey Bugaev <bugaevc@gmail.com>
Sat, 20 May 2023 11:55:29 +0000 (14:55 +0300)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 20 May 2023 16:14:01 +0000 (18:14 +0200)
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>

49 files changed:
hurd/alloc-fd.c
hurd/fopenport.c
hurd/getdport.c
hurd/hurdselect.c
hurd/hurdsock.c
sysdeps/mach/hurd/brk.c
sysdeps/mach/hurd/closedir.c
sysdeps/mach/hurd/cthreads.c
sysdeps/mach/hurd/dirfd.c
sysdeps/mach/hurd/dl-sysdep.c
sysdeps/mach/hurd/dup3.c
sysdeps/mach/hurd/f_setlk.c
sysdeps/mach/hurd/fcntl.c
sysdeps/mach/hurd/fdopendir.c
sysdeps/mach/hurd/getcwd.c
sysdeps/mach/hurd/getegid.c
sysdeps/mach/hurd/getentropy.c
sysdeps/mach/hurd/geteuid.c
sysdeps/mach/hurd/getgid.c
sysdeps/mach/hurd/getlogin.c
sysdeps/mach/hurd/getlogin_r.c
sysdeps/mach/hurd/getrlimit.c
sysdeps/mach/hurd/getuid.c
sysdeps/mach/hurd/i386/sigreturn.c
sysdeps/mach/hurd/if_index.c
sysdeps/mach/hurd/ifreq.c
sysdeps/mach/hurd/libc_sigaction.c
sysdeps/mach/hurd/lseek.c
sysdeps/mach/hurd/mknodat.c
sysdeps/mach/hurd/mmap64.c
sysdeps/mach/hurd/opendir.c
sysdeps/mach/hurd/ptrace.c
sysdeps/mach/hurd/ptsname.c
sysdeps/mach/hurd/readdir.c
sysdeps/mach/hurd/readdir64.c
sysdeps/mach/hurd/readdir64_r.c
sysdeps/mach/hurd/sendmsg.c
sysdeps/mach/hurd/setrlimit.c
sysdeps/mach/hurd/sigaltstack.c
sysdeps/mach/hurd/sigpending.c
sysdeps/mach/hurd/sigprocmask.c
sysdeps/mach/hurd/sigsuspend.c
sysdeps/mach/hurd/spawni.c
sysdeps/mach/hurd/statconv.c
sysdeps/mach/hurd/statfsconv.c
sysdeps/mach/hurd/ttyname_r.c
sysdeps/mach/hurd/unlinkat.c
sysdeps/mach/hurd/waitid.c
sysdeps/mach/hurd/x86_64/sigreturn.c

index 60c8b0089750387e08bf112ba4a470cb386e6f5f..4edc742122117c4f9c32a283c7563722b92d249f 100644 (file)
@@ -34,10 +34,7 @@ _hurd_alloc_fd (int *fd, int first_fd)
   long int rlimit;
 
   if (first_fd < 0)
-    {
-      errno = EINVAL;
-      return NULL;
-    }
+    return __hurd_fail (EINVAL), NULL;
 
   crit = _hurd_critical_section_lock ();
 
@@ -99,7 +96,7 @@ _hurd_alloc_fd (int *fd, int first_fd)
          if (size * sizeof (*_hurd_dtable) < size)
            {
              /* Integer overflow! */
-             errno = ENOMEM;
+             __hurd_fail (ENOMEM);
              goto out;
            }
 
@@ -124,13 +121,13 @@ _hurd_alloc_fd (int *fd, int first_fd)
              goto search;
            }
          else
-           errno = ENOMEM;
+           __hurd_fail (ENOMEM);
        }
       else
-       errno = EMFILE;
+       __hurd_fail (EMFILE);
     }
   else
-    errno = EINVAL;            /* Bogus FIRST_FD value.  */
+    __hurd_fail (EINVAL);      /* Bogus FIRST_FD value.  */
 
  out:
   __mutex_unlock (&_hurd_dtable_lock);
index be6aa30c7efaa2cb0bba9746031a7cc4f4a20857..a1efc5424d61bf5964de0a15b0908a56ae848e85 100644 (file)
@@ -126,10 +126,7 @@ __fopenport (mach_port_t port, const char *mode)
 
   /* Check the access mode.  */
   if ((pflags & needflags) != needflags)
-    {
-      errno = EBADF;
-      return NULL;
-    }
+    return __hurd_fail (EBADF), NULL;
 
   return fopencookie ((void *) (uintptr_t) port,
                       mode, funcsio);
index 2bccc597897eb0047fcf7cdd7454de0650675fd5..27fc41f42012d0bedeb3716ea407784044ae21cb 100644 (file)
@@ -35,18 +35,12 @@ __getdport (int fd)
      so we don't bother allocating a real table.  */
 
   if (_hurd_init_dtable == NULL)
-    {
-      /* Never had a descriptor table.  */
-      errno = EBADF;
-      return MACH_PORT_NULL;
-    }
+    /* Never had a descriptor table.  */
+    return __hurd_fail (EBADF), MACH_PORT_NULL;
 
   if (fd < 0 || (unsigned int) fd > _hurd_init_dtablesize
       || _hurd_init_dtable[fd] == MACH_PORT_NULL)
-    {
-      errno = EBADF;
-      return MACH_PORT_NULL;
-    }
+    return __hurd_fail (EBADF), MACH_PORT_NULL;
   else
     {
       __mach_port_mod_refs (__mach_task_self (), _hurd_init_dtable[fd],
index 9630cae47403bfa0a647c4c10d14f53a771d5ed8..940276396c725bf4c93a88e50a50ccd2cdc039f0 100644 (file)
@@ -71,10 +71,7 @@ _hurd_select (int nfds,
   struct hurd_sigstate *ss = NULL;
 
   if (nfds < 0 || (pollfds == NULL && nfds > FD_SETSIZE))
-    {
-      errno = EINVAL;
-      return -1;
-    }
+    return __hurd_fail (EINVAL);
 
 #define IO_SELECT_REPLY_MSGID (21012 + 100) /* XXX */
 #define IO_SELECT_TIMEOUT_REPLY_MSGID (21031 + 100) /* XXX */
@@ -86,10 +83,7 @@ _hurd_select (int nfds,
       struct timespec now;
 
       if (timeout->tv_sec < 0 || ! valid_nanoseconds (timeout->tv_nsec))
-       {
-         errno = EINVAL;
-         return -1;
-       }
+       return __hurd_fail (EINVAL);
 
       err = __clock_gettime (CLOCK_REALTIME, &now);
       if (err)
@@ -281,8 +275,7 @@ _hurd_select (int nfds,
        {
          if (sigmask)
            __sigprocmask (SIG_SETMASK, &oset, NULL);
-         errno = EBADF;
-         return -1;
+         return __hurd_fail (EBADF);
        }
 
       if (nfds > _hurd_dtablesize)
index 58c27feb2b5f48b06069c32e14597c95d72d5a10..1d04047a02ac293d92a24d5fb2b0b767dc7ebef3 100644 (file)
@@ -48,10 +48,7 @@ _hurd_socket_server (int domain, int dead)
   socket_t server;
 
   if (domain < 0)
-    {
-      errno = EAFNOSUPPORT;
-      return MACH_PORT_NULL;
-    }
+    return __hurd_fail (EAFNOSUPPORT), MACH_PORT_NULL;
 
 retry:
   HURD_CRITICAL_BEGIN;
@@ -99,7 +96,7 @@ retry:
 
   if (server == MACH_PORT_NULL && errno == ENOENT)
     /* If the server node is absent, we don't support that protocol.  */
-    errno = EAFNOSUPPORT;
+    __hurd_fail (EAFNOSUPPORT);
 
   __mutex_unlock (&lock);
   HURD_CRITICAL_END;
index 12aaba5212f58fc7e2704c23322d1408abda07fb..f1349495f5575a2a8c4ed09efd9cc85a06da8cb9 100644 (file)
@@ -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)
     {
index 3a16418f9f51d82660b48edc4e3d4d3336b821bd..46815f05480f45e6491b68d2f8a17ed981e636a7 100644 (file)
@@ -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 (),
index 87b6c06b67a37a12d39e7731a031d335d36bd22b..4f5920bce2efd31d9718c90a4c16f49a8345b146 100644 (file)
@@ -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);
 }
index 9520f3ef8976ed89652d1db3c2795265529f2b37..2cf02c787a3fb8b16270a9dd1d0d17fbabb1830d 100644 (file)
@@ -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;
 
index 79ebb0ceb18b2ea39ad306e0890ee923956518ab..7c484d76ebba6ae7890c7c09fe433a5efa33226b 100644 (file)
@@ -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
index 0bcbbfd663a14765a82418652ce90746df66304f..c5f64bcecb9444dc52f5ad0e51b0b6d3a1b327eb 100644 (file)
@@ -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
            {
index 5c60a6347cc7d884599eccaeeed75fc04a6a3c67..9f1b0baa6c7ee35ef242efb5b49ebba5fb97158b 100644 (file)
@@ -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);
index a89d6d39dfae45a88a884e9b5789031940e0cc73..0b9a64bc57c8d39ba3592b86e09b8291c0d62772 100644 (file)
@@ -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);
              }
          }
 
index 2a152b07a176fdc0cf46fcaa0d8f856750f7892b..33ea2f0cf2a873af99c860ab97b61c9502a5a5fc 100644 (file)
@@ -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);
 }
index cd3aedd9cde7d260abcd736e1e9c0885c7b110d7..b9a6f855b04576a667e97cc0631dfad64ccf350d 100644 (file)
@@ -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;
index 7f07d13b1aec31756c776c2986fc4ac82c4c6c90..9ca56e572907ca37b8ebd2d5c19aa1172df12316 100644 (file)
@@ -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;
index adbbb78ca009b056e8c96cef29161f8d02e9f1dd..118f8984e7e46002e79911c44d5e6884e9f3411d 100644 (file)
@@ -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
@@ -51,12 +49,9 @@ getentropy (void *buffer, size_t length)
             return -1;
         }
       if (bytes == 0)
-        {
-          /* No more bytes available.  This should not happen under
-             normal circumstances.  */
-          __set_errno (EIO);
-          return -1;
-        }
+        /* No more bytes available.  This should not happen under
+           normal circumstances.  */
+        return __hurd_fail (EIO);
       /* Try again in case of a short read.  */
       buffer += bytes;
     }
index a50c514faafa61eecc199ff1089027072f867cf6..3548bdde41e29e078630e2a42204f3e94afab6a3 100644 (file)
@@ -32,21 +32,15 @@ retry:
   __mutex_lock (&_hurd_id.lock);
 
   if (err = _hurd_check_ids ())
-    {
-      errno = err;
-      euid = -1;
-    }
+    euid = __hurd_fail (err);
   else if (_hurd_id.gen.nuids >= 1)
     euid = _hurd_id.gen.uids[0];
   else if (_hurd_id.aux.nuids >= 1)
     /* We have no effective uids.  Return the real uid.  */
     euid = _hurd_id.aux.uids[0];
   else
-    {
-      /* We do not even have a real uid.  */
-      errno = EGRATUITOUS;
-      euid = -1;
-    }
+    /* We do not even have a real uid.  */
+    euid = __hurd_fail (EGRATUITOUS);
 
   __mutex_unlock (&_hurd_id.lock);
   HURD_CRITICAL_END;
index f49e592f79099df6f1fd3ef9c4efecbbf1703cbb..62183074ea657a78f3250a095c4d341f43cff878 100644 (file)
@@ -32,18 +32,12 @@ retry:
   __mutex_lock (&_hurd_id.lock);
 
   if (err = _hurd_check_ids ())
-    {
-      errno = err;
-      gid = -1;
-    }
+    gid = __hurd_fail (err);
   else if (_hurd_id.aux.ngids >= 1)
     gid = _hurd_id.aux.gids[0];
   else
-    {
-      /* We do not even have a real gid.  */
-      errno = EGRATUITOUS;
-      gid = -1;
-    }
+    /* We do not even have a real gid.  */
+    gid = __hurd_fail (EGRATUITOUS);
 
   __mutex_unlock (&_hurd_id.lock);
   HURD_CRITICAL_END;
index 336afaeac70a805677e152e72b95e6623219f313..3f1b9a6f3c3b81a7835e0d838c3ac69dec99bf8c 100644 (file)
@@ -29,10 +29,7 @@ getlogin (void)
   error_t err;
 
   if (err = __USEPORT (PROC, __proc_getlogin (port, login)))
-    {
-      errno = err;
-      return NULL;
-    }
+    return __hurd_fail (err), NULL;
 
   return login;
 }
index 2e4322518252815ae163b347589a37fd2ca4a916..c1a2f14e5eac633e05ac958105d1f8fc190d1ae5 100644 (file)
@@ -31,14 +31,11 @@ __getlogin_r (char *name, size_t name_len)
   error_t err;
 
   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;
   if (len > name_len)
-    {
-      errno = ERANGE;
-      return errno;
-    }
+    return __hurd_fail (ERANGE), ERANGE;
 
   memcpy (name, login, len);
   return 0;
index 547d4e617e272e6c39f9706a51bbfb7b772b1c23..5744f67d121dae8ec569c1672b7ce055327f0843 100644 (file)
@@ -28,10 +28,7 @@ __getrlimit (enum __rlimit_resource resource, struct rlimit *rlimits)
   struct rlimit lim;
 
   if (rlimits == NULL || (unsigned int) resource >= RLIMIT_NLIMITS)
-    {
-      errno = EINVAL;
-      return -1;
-    }
+    return __hurd_fail (EINVAL);
 
   HURD_CRITICAL_BEGIN;
   __mutex_lock (&_hurd_rlimit_lock);
index 267cbda9cb2f60a98e4fbb7fcc3a92ca3d377e46..fa778ebc16d37874e3eb10c72cee06dee4cfa581 100644 (file)
@@ -32,18 +32,12 @@ retry:
   __mutex_lock (&_hurd_id.lock);
 
   if (err = _hurd_check_ids ())
-    {
-      errno = err;
-      uid = -1;
-    }
+    uid = __hurd_fail (err);
   else if (_hurd_id.aux.nuids >= 1)
     uid = _hurd_id.aux.uids[0];
   else
-    {
-      /* We do not even have a real uid.  */
-      errno = EGRATUITOUS;
-      uid = -1;
-    }
+    /* We do not even have a real uid.  */
+    uid = __hurd_fail (EGRATUITOUS);
 
   __mutex_unlock (&_hurd_id.lock);
   HURD_CRITICAL_END;
index 1686734d3c3108e10d6e0f936b23ddb8f501a0fc..64faa5d8ca93edb1a037aea86d3da839b3af0309 100644 (file)
@@ -84,10 +84,7 @@ __sigreturn (struct sigcontext *scp)
   struct hurd_userlink *link = (void *) &scp[1];
 
   if (__glibc_unlikely (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK)))
-    {
-      errno = EINVAL;
-      return -1;
-    }
+    return __hurd_fail (EINVAL);
 
   ss = _hurd_self_sigstate ();
   _hurd_sigstate_lock (ss);
index c8ad7e722bf6de914b11886cc2d5cc44cc5a8819..5c10da5deb81e2004af153fbee2c899cd0258093 100644 (file)
@@ -38,10 +38,7 @@ __if_nametoindex (const char *ifname)
     return 0;
 
   if (strlen (ifname) >= IFNAMSIZ)
-    {
-      __set_errno (ENODEV);
-      return 0;
-    }
+    return __hurd_fail (ENODEV), 0;
 
   strncpy (ifr.ifr_name, ifname, IFNAMSIZ);
   if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0)
@@ -49,7 +46,7 @@ __if_nametoindex (const char *ifname)
       int saved_errno = errno;
       __close (fd);
       if (saved_errno == EINVAL || saved_errno == ENOTTY)
-        __set_errno (ENOSYS);
+        __hurd_fail (ENOSYS);
       return 0;
     }
   __close (fd);
@@ -180,9 +177,9 @@ __if_indextoname (unsigned int ifindex, char ifname[IF_NAMESIZE])
       int saved_errno = errno;
       __close (fd);
       if (saved_errno == EINVAL || saved_errno == ENOTTY)
-        __set_errno (ENOSYS);
+        __hurd_fail (ENOSYS);
       else if (saved_errno == ENODEV)
-       __set_errno (ENXIO);
+       __hurd_fail (ENXIO);
       return NULL;
     }
   __close (fd);
index 394d020cf063e5eea6eacb76758547b1ccbf6c4b..eec7dd80565514da16275b1cb08c3e6e261e218f 100644 (file)
@@ -54,7 +54,7 @@ __ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd)
       if (len % sizeof (struct ifreq) != 0)
        {
          __munmap (data, len);
-         errno = EGRATUITOUS;
+         __hurd_fail (EGRATUITOUS);
          goto out;
        }
       *num_ifs = len / sizeof (struct ifreq);
index 3053c7e7acb1ead71411e360357fa5468e0cc7bb..748647e9f8f3f06d628be8739590d1e92d26b7b5 100644 (file)
@@ -33,10 +33,7 @@ __libc_sigaction (int sig, const struct sigaction *act,
 
   if (act != NULL && act->sa_handler != SIG_DFL
       && ((__sigmask (sig) & _SIG_CANT_MASK) || act->sa_handler == SIG_ERR))
-    {
-      errno = EINVAL;
-      return -1;
-    }
+    return __hurd_fail (EINVAL);
 
   /* Copy so we fault before taking locks.  */
   if (act != NULL)
index 7b4e1289b27a0ba78fb69fd74e60366fea9b4ef8..0fe20e2a176f600343f5d1a75e73088c01ef62bd 100644 (file)
@@ -18,6 +18,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <errno.h>
+#include <hurd.h>
 
 /* Seek to OFFSET on FD, starting from WHENCE.  */
 off_t
@@ -27,10 +28,7 @@ __libc_lseek (int fd, off_t offset, int whence)
   off_t res = (off_t) res64;
 
   if (sizeof res != sizeof res64 && res != res64)
-    {
-      __set_errno (EOVERFLOW);
-      return (off_t) -1;
-    }
+    return (off_t) __hurd_fail (EOVERFLOW);
 
   return res;
 }
index f3ccb86905acc571e84e7a0ccf3166d5d7de3cec..67158e1b3ea08707e0e832bf0f113627d645a89f 100644 (file)
@@ -63,10 +63,7 @@ __mknodat (int fd, const char *path, mode_t mode, dev_t dev)
       len = 0;
     }
   else
-    {
-      errno = EINVAL;
-      return -1;
-    }
+    return __hurd_fail (EINVAL);
 
   if (translator != NULL && ! S_ISFIFO (mode))
     {
index a838afd4ee360fa0f5e568b08b98622b5f48aa5c..cafd03478ab73088b039ebbc45dcd2b13ee28cd5 100644 (file)
@@ -19,6 +19,7 @@
 #include <sys/mman.h>
 #include <sys/types.h>
 #include <mach/port.h>
+#include <hurd.h>
 
 /* Map addresses starting near ADDR and extending for LEN bytes.  From
    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;
 
   if (small_offset != offset)
-    {
-      /* We cannot do this since the offset is too large.  */
-      __set_errno (EOVERFLOW);
-      return MAP_FAILED;
-    }
+    /* We cannot do this since the offset is too large.  */
+    return __hurd_fail (EOVERFLOW), MAP_FAILED;
 
   return __mmap (addr, len, prot, flags, fd, small_offset);
 }
index cfba659c9d57ea0bdf798b684af908573b6b7c78..39c805bc8e24a3befe94713ff97bbdb38b60e409 100644 (file)
@@ -40,10 +40,7 @@ _hurd_fd_opendir (struct hurd_fd *d)
   DIR *dirp;
 
   if (d == NULL)
-    {
-      errno = EBADF;
-      return NULL;
-    }
+    return __hurd_fail (EBADF), NULL;
 
   dirp = (DIR *) malloc (sizeof (DIR));
   if (dirp == NULL)
@@ -72,12 +69,9 @@ DIR *
 __opendirat (int dfd, const char *name)
 {
   if (name[0] == '\0')
-    {
-      /* POSIX.1-1990 says an empty name gets ENOENT;
-        but `open' might like it fine.  */
-      __set_errno (ENOENT);
-      return NULL;
-    }
+    /* POSIX.1-1990 says an empty name gets ENOENT;
+       but `open' might like it fine.  */
+    return __hurd_fail (ENOENT), NULL;
 
   int flags = O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC;
   int fd;
@@ -107,12 +101,9 @@ __opendir (const char *name)
   return __opendirat (AT_FDCWD, name);
 #else
   if (name[0] == '\0')
-    {
-      /* POSIX.1-1990 says an empty name gets ENOENT;
-        but `open' might like it fine.  */
-      __set_errno (ENOENT);
-      return NULL;
-    }
+    /* POSIX.1-1990 says an empty name gets ENOENT;
+       but `open' might like it fine.  */
+    return __hurd_fail (ENOENT), NULL;
 
   int fd = __open (name, O_RDONLY | O_NONBLOCK | O_DIRECTORY);
   if (fd < 0)
index b2efac0722ddb7da61414c73969cb7062757ff51..97948d3fac808a0a0f9588671fd191cd97a965a9 100644 (file)
@@ -380,8 +380,7 @@ ptrace (enum __ptrace_request request, ... )
       }
 
     default:
-      errno = EINVAL;
-      return -1;
+      return __hurd_fail (EINVAL);
     }
 
   return 0;
index f6ad993954ac284e2a1a9e2b134504c52f211424..06234f536b84424577abccf8a6463363476eb09a 100644 (file)
@@ -49,11 +49,8 @@ __ptsname_internal (int fd, char *buf, size_t buflen, struct stat64 *stp)
   int ttype;
 
   if (HURD_DPORT_USE (fd, __term_get_bottom_type (port, &ttype)) == 0)
-    {
-      /* get_bottom_type suceeded, this is the slave side.  */
-      errno = ENOTTY;
-      return ENOTTY;
-    }
+    /* get_bottom_type suceeded, this is the slave side.  */
+    return __hurd_fail (ENOTTY), ENOTTY;
 
   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;
   if (len > buflen)
-    {
-      errno = ERANGE;
-      return ERANGE;
-    }
+    return __hurd_fail (ERANGE), ERANGE;
 
   if (stp)
     {
index d52cfe7df0353a1fa6374079dcf255d827c7bbf3..bf67823e471fedf9c2ab93bb1001797b9ac3ecbd 100644 (file)
@@ -21,6 +21,7 @@
 #include <unistd.h>
 #include <endian.h>
 #include <assert.h>
+#include <hurd.h>
 
 /* Read a directory entry from DIRP.  */
 struct dirent *
@@ -52,10 +53,7 @@ __readdir (DIR *dirp)
                                - sizeof entry->d_ino);
   const ino_t d_ino = entry64->d_ino;
   if (d_ino != entry64->d_ino)
-    {
-      __set_errno (EOVERFLOW);
-      return NULL;
-    }
+    return __hurd_fail (EOVERFLOW), NULL;
 # 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.  */
 # endif
index ceb7083e2a4393cdc4d50061df6949964face451..2c01ca22c9a6ca08805d8f29d6e4db843481c6b0 100644 (file)
@@ -29,10 +29,7 @@ __readdir64 (DIR *dirp)
   struct dirent64 *dp;
 
   if (dirp == NULL)
-    {
-      errno = EINVAL;
-      return NULL;
-    }
+    return __hurd_fail (EINVAL), NULL;
 
   __libc_lock_lock (dirp->__lock);
 
index 4f4252c25632d7f396ad03d2b047b1f5558a8041..fdfe498d1ed4cbb098c6ccd667d4c2247f34555a 100644 (file)
@@ -31,10 +31,7 @@ __readdir64_r (DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
   error_t err = 0;
 
   if (dirp == NULL)
-    {
-      errno = EINVAL;
-      return errno;
-    }
+    return __hurd_fail (EINVAL), EINVAL;
 
   __libc_lock_lock (dirp->__lock);
 
index 3c9cdc4e66a796ae5f1136375368fd1b1966edf6..7f86f60bcd08f23628754a321d6dec208c214ec7 100644 (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);
          if (err)
-           {
-             __set_errno (err);
-             return -1;
-           }
+           return __hurd_fail (err);
          dealloc = 1;
        }
       else
index 7dc62e1e87099439a471784fcaf4936d1a4a7e0c..f57439f31a9238bbdcdb4512fccd8c2902ad9c03 100644 (file)
@@ -30,10 +30,7 @@ __setrlimit (enum __rlimit_resource resource, const struct rlimit *rlimits)
   struct rlimit lim;
 
   if (rlimits == NULL || (unsigned int) resource >= RLIMIT_NLIMITS)
-    {
-      errno = EINVAL;
-      return -1;
-    }
+    return __hurd_fail (EINVAL);
 
   lim = *rlimits;
 
index 8d5a2a8e8b503e7203c9932e9f4e5b35253851c7..7431a11cdab708fd308b19e38c0948c4af68710c 100644 (file)
@@ -42,8 +42,7 @@ __sigaltstack (const stack_t *argss, stack_t *oss)
     {
       /* Can't disable a stack that is in use.  */
       __spin_unlock (&s->lock);
-      errno = EINVAL;
-      return -1;
+      return __hurd_fail (EINVAL);
     }
 
   old = s->sigaltstack;
index 59078a3f7278bfeef0fa298e7bc0210733c060e9..6a8d3b8b1f4db69d23af3e4477b1bab84c0dd19e 100644 (file)
@@ -30,10 +30,7 @@ sigpending (sigset_t *set)
   sigset_t pending;
 
   if (set == NULL)
-    {
-      errno = EINVAL;
-      return -1;
-    }
+    return __hurd_fail (EINVAL);
 
   ss = _hurd_self_sigstate ();
   _hurd_sigstate_lock (ss);
index c7c5dfc323f4a97b937c085993e2ed765156c3c2..d53095115cfbfbc859b0fb01d7546209c435ab19 100644 (file)
@@ -58,8 +58,7 @@ __sigprocmask (int how, const sigset_t *set, sigset_t *oset)
 
        default:
          _hurd_sigstate_unlock (ss);
-         errno = EINVAL;
-         return -1;
+         return __hurd_fail (EINVAL);
        }
 
       ss->blocked &= ~_SIG_CANT_MASK;
index 85f3e78f8b779074d0f220cb4add9609747b17a2..2dec3f917c68257b4663fff6bd9be2177d835f61 100644 (file)
@@ -81,8 +81,7 @@ __sigsuspend (const sigset_t *set)
   /* We've been interrupted!  And a good thing, too.
      Otherwise we'd never return.
      That's right; this function always returns an error.  */
-  errno = EINTR;
-  return -1;
+  return __hurd_fail (EINTR);
 }
 libc_hidden_def (__sigsuspend)
 weak_alias (__sigsuspend, sigsuspend)
index f45311a0c89986017168ff866247d04f833fc737..5e05308066e82cbb21bb449dc2ce46fc67514cdf 100644 (file)
@@ -216,8 +216,7 @@ __spawni (pid_t *pid, const char *file,
                                MACH_PORT_RIGHT_SEND, +1);
          return dtable[fd];
        }
-      errno = EBADF;
-      return MACH_PORT_NULL;
+      return __hurd_fail (EBADF), MACH_PORT_NULL;
     }
   inline error_t child_lookup (const char *file, int oflag, mode_t mode,
                               file_t *result)
index 306dde38e6bfa8350a0ea8e9d28ad00360de0435..ae3950f121292b4814732327efcb78e5bb87a28c 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <sys/stat.h>
+#include <hurd.h>
 
 static inline int
 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)
       || (sizeof buf->st_blocks != sizeof buf64->st_blocks
          && buf->st_blocks != buf64->st_blocks))
-    {
-      __set_errno (EOVERFLOW);
-      return -1;
-    }
+    return __hurd_fail (EOVERFLOW);
 
   return 0;
 }
index f67d6b98511c6610ea6efb2fe5b9c819e61fe358..8a2051c26985e008c43125f47511c3f4e52db9fe 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <sys/statfs.h>
 #include <errno.h>
+#include <hurd.h>
 
 static inline int
 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)                                                            \
   buf->memb = buf64->memb;                                                   \
   if (sizeof buf->memb != sizeof buf64->memb && buf->memb != buf64->memb)     \
-    {                                                                        \
-      __set_errno (EOVERFLOW);                                               \
-      return -1;                                                             \
-    }
+    return __hurd_fail (EOVERFLOW);
 
   DO (f_type);
   DO (f_bsize);
index 35a657bf61efa6aebbbeb7f58c17c6fb218a53a4..8fd05a8d85782392403eb70bb6626d9e3c74e5b6 100644 (file)
@@ -41,10 +41,7 @@ __ttyname_r (int fd, char *buf, size_t buflen)
 
   len = strlen (nodename) + 1;
   if (len > buflen)
-    {
-      errno = ERANGE;
-      return errno;
-    }
+    return __hurd_fail (ERANGE), ERANGE;
 
   memcpy (buf, nodename, len);
   return 0;
index 5197a30c37b28558b64b4b294867e34eb067a9b8..cdc277421f7f3a3e0441cf363de43cba2b1be188 100644 (file)
@@ -33,10 +33,7 @@ __unlinkat (int fd, const char *name, int flag)
   const char *file;
 
   if ((flag &~ AT_REMOVEDIR) != 0)
-    {
-      __set_errno (EINVAL);
-      return -1;
-    }
+    return __hurd_fail (EINVAL);
 
   dir = __directory_name_split_at (fd, name, (char **) &file);
   if (dir == MACH_PORT_NULL)
index 7bbbbdbe542cb58f6c8e00919ae823fcbb647bc9..3a416971406e0095e3f42f34d55964bf7277ce89 100644 (file)
@@ -52,8 +52,7 @@ __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
       break;
     default:
     invalid:
-      __set_errno (EINVAL);
-      return -1;
+      return __hurd_fail (EINVAL);
     }
 
   /* 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. */
 
   if (infop == NULL)
-    {
-      __set_errno (EFAULT);
-      return -1;
-    }
+    return __hurd_fail (EFAULT);
 
   cancel_oldtype = LIBC_CANCEL_ASYNC();
 #if HURD_INTERFACE_VERSION >= 20201227
index 5d3a4d31dc3b8fbbc96bfd0325533cde7d663060..f37ae119ca4773bcb953c20fcca3b2633af6e760 100644 (file)
@@ -79,10 +79,7 @@ __sigreturn (struct sigcontext *scp)
   struct hurd_userlink *link = (void *) &scp[1];
 
   if (__glibc_unlikely (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK)))
-    {
-      errno = EINVAL;
-      return -1;
-    }
+    return __hurd_fail (EINVAL);
 
   ss = _hurd_self_sigstate ();
   _hurd_sigstate_lock (ss);