diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-10 11:06:31 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-10 11:06:31 +0000 |
| commit | 632c85ce1cbfc4b8c651c0bb258805fa657a747a (patch) | |
| tree | ef5b382465cfe71718374b5f30f50a6f29446113 | |
| parent | 8d156bcf358e20979f444209e227f2187728a7b2 (diff) | |
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>
| -rw-r--r-- | util/nvmutil/nvmutil.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 64ef5bec..28368f8d 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -1371,6 +1371,7 @@ prw(int fd, void *mem, size_t count, { off_t old; ssize_t r; + int restore_errno; int saved_errno = 0; 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) saved_errno = errno; + restore_errno = errno; + if (lseek_eintr(fd, old, SEEK_SET) == (off_t)-1) { if (saved_errno) errno = saved_errno; + else + errno = restore_errno; return -1; } |
