summaryrefslogtreecommitdiff
path: root/util/nvmutil
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-10 10:26:12 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-10 10:26:12 +0000
commit91a6395e5cbfd70f5227d1a6b347444dcb7dea5f (patch)
treee63335109ceb9d9db5be8e6da0354dbe6e8c3fc1 /util/nvmutil
parent5a005eff9e404873876ec676917f55f27333ddf5 (diff)
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>
Diffstat (limited to 'util/nvmutil')
-rw-r--r--util/nvmutil/nvmutil.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 2bc74615..71e16f46 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -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;
}