From: Bruno Haible Date: Thu, 13 May 2021 19:33:55 +0000 (+0200) Subject: getrandom: Produce a better error code. X-Git-Tag: v1.0~2895 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc5bf815d325867d4d96edb7963b695dfce7d849;p=thirdparty%2Fgnulib.git getrandom: Produce a better error code. Reported by Paul Eggert in . * 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. --- diff --git a/ChangeLog b/ChangeLog index 711e53f9c1..b12c196128 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2021-05-13 Bruno Haible + + getrandom: Produce a better error code. + Reported by Paul Eggert in + . + * 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 fstatat: Document a glibc 2.7 bug. diff --git a/lib/getrandom.c b/lib/getrandom.c index 6160118336..9e90e646aa 100644 --- a/lib/getrandom.c +++ b/lib/getrandom.c @@ -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;