]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
getrandom: Produce a better error code.
authorBruno Haible <bruno@clisp.org>
Thu, 13 May 2021 19:33:55 +0000 (21:33 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 13 May 2021 19:33:55 +0000 (21:33 +0200)
Reported by Paul Eggert in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-05/msg00025.html>.

* lib/getrandom.c (getrandom): When open() fails with an error that does
not indicate the absence of the file, fail with that error code, not
with ENOSYS.

ChangeLog
lib/getrandom.c

index 711e53f9c1a086d4bff7c18bc43bc1344129a2c6..b12c1961283ebe76e0bdf49e7420ed7204636af9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-05-13  Bruno Haible  <bruno@clisp.org>
+
+       getrandom: Produce a better error code.
+       Reported by Paul Eggert in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2021-05/msg00025.html>.
+       * lib/getrandom.c (getrandom): When open() fails with an error that does
+       not indicate the absence of the file, fail with that error code, not
+       with ENOSYS.
+
 2021-05-13  Bruno Haible  <bruno@clisp.org>
 
        fstatat: Document a glibc 2.7 bug.
index 6160118336503b135c40c2563b26abf640132f76..9e90e646aa7ca144f721a274ee9d80699f398a91 100644 (file)
@@ -179,7 +179,8 @@ getrandom (void *buffer, size_t length, unsigned int flags)
       fd = open (randdevice[devrandom], oflags);
       if (fd < 0)
         {
-          errno = ENOSYS;
+          if (errno == ENOENT || errno == ENOTDIR)
+            errno = ENOSYS;
           return -1;
         }
       randfd[devrandom] = fd;