mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-15 17:58:46 +02:00
util/nvmutil: restore errno if lseek resets it
if it resets it on success, that is! theoretically possible. we must preserve errno. normally i'm a bit more casual about it, but this function is replicating libc, so i must be strict Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -1371,6 +1371,7 @@ prw(int fd, void *mem, size_t count,
|
|||||||
{
|
{
|
||||||
off_t old;
|
off_t old;
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
|
int restore_errno;
|
||||||
int saved_errno = 0;
|
int saved_errno = 0;
|
||||||
|
|
||||||
if ((old = lseek_eintr(fd, (off_t)0, SEEK_CUR)) == (off_t)-1)
|
if ((old = lseek_eintr(fd, (off_t)0, SEEK_CUR)) == (off_t)-1)
|
||||||
@@ -1391,9 +1392,13 @@ prw(int fd, void *mem, size_t count,
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
saved_errno = errno;
|
saved_errno = errno;
|
||||||
|
|
||||||
|
restore_errno = errno;
|
||||||
|
|
||||||
if (lseek_eintr(fd, old, SEEK_SET) == (off_t)-1) {
|
if (lseek_eintr(fd, old, SEEK_SET) == (off_t)-1) {
|
||||||
if (saved_errno)
|
if (saved_errno)
|
||||||
errno = saved_errno;
|
errno = saved_errno;
|
||||||
|
else
|
||||||
|
errno = restore_errno;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user