mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
utils: pw_getrandom() use errno from read() call
The errno from read is more useful than the one from close() clobbering it. So make sure to preserve the real reason for failure for the caller.
This commit is contained in:
parent
6531bedcdb
commit
987069cc3c
1 changed files with 3 additions and 0 deletions
|
|
@ -154,6 +154,7 @@ SPA_EXPORT
|
|||
ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags)
|
||||
{
|
||||
ssize_t bytes;
|
||||
int read_errno;
|
||||
|
||||
#ifdef HAVE_GETRANDOM
|
||||
bytes = getrandom(buf, buflen, flags);
|
||||
|
|
@ -165,7 +166,9 @@ ssize_t pw_getrandom(void *buf, size_t buflen, unsigned int flags)
|
|||
if (fd < 0)
|
||||
return -1;
|
||||
bytes = read(fd, buf, buflen);
|
||||
read_errno = errno;
|
||||
close(fd);
|
||||
errno = read_errno;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue