about summary refs log tree commit diff
path: root/hurd/alloc-fd.c
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 /hurd/alloc-fd.c
parent36cc908ed549389713955093bbfeaa35fdaf3e2e (diff)
downloadglibc-9ec31e57278ffc4e680ef03e75ce5b6b02e5edcf.tar.gz
glibc-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 'hurd/alloc-fd.c')
-rw-r--r--hurd/alloc-fd.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/hurd/alloc-fd.c b/hurd/alloc-fd.c
index 60c8b00897..4edc742122 100644
--- a/hurd/alloc-fd.c
+++ b/hurd/alloc-fd.c
@@ -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);