util/nvmutil: preserve errno during i/o

do not clobber errno

yeah we're basically being libc now

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-10 10:26:12 +00:00
parent 5a005eff9e
commit 91a6395e5c
+7
View File
@@ -1372,6 +1372,7 @@ prw(int fd, void *mem, size_t count,
{
off_t old;
ssize_t r;
int saved_errno = 0;
if ((old = lseek_eintr(fd, (off_t)0, SEEK_CUR)) == (off_t)-1)
return -1;
@@ -1388,9 +1389,15 @@ prw(int fd, void *mem, size_t count,
err(EIO, "%s: Invalid rw_type", path);
} while (r < 0 && errno == EINTR);
if (r < 0)
saved_errno = errno;
if (lseek_eintr(fd, old, SEEK_SET) == (off_t)-1)
return -1;
if (r < 0)
errno = saved_errno;
return r;
}