diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-14 23:43:08 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-14 23:43:08 +0000 |
| commit | 8875a712ae82a041e62ab0b882ee7e27a7f9a7a4 (patch) | |
| tree | 41e205935e26a0962a9e3067ecf4f9e9158cbc9e /util/nvmutil/nvmutil.c | |
| parent | 23e7170897c2f812b565fe0415f52184ca26ed7b (diff) | |
util/nvmutil: tidy up err()
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil/nvmutil.c')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 9659c5c2..876d1d44 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -430,8 +430,8 @@ static int try_err(int loop_err, int errval); /* * Error handling and cleanup */ -static int close_files(void); static void err(int nvm_errval, const char *msg, ...); +static int close_files(void); static const char *getnvmprogname(void); static void usage(int usage_exit); @@ -2252,35 +2252,12 @@ try_err(int loop_err, int errval) return -1; } -static int -close_files(void) -{ - int close_err_gbe = 0; - int saved_errno = errno; - - if (gbe_fd > -1) { - if (close(gbe_fd) == -1) - close_err_gbe = errno; - gbe_fd = -1; - } - - if (saved_errno) - errno = saved_errno; - - if (close_err_gbe) - return -1; - - return 0; -} - static void err(int nvm_errval, const char *msg, ...) { va_list args; - if (errno < 0) - errno = ECANCELED; - if (!errno) + if (errno == 0) errno = nvm_errval; (void)close_files(); @@ -2297,6 +2274,27 @@ err(int nvm_errval, const char *msg, ...) exit(EXIT_FAILURE); } +static int +close_files(void) +{ + int close_err_gbe = 0; + int saved_errno = errno; + + if (gbe_fd > -1) { + if (close(gbe_fd) == -1) + close_err_gbe = errno; + gbe_fd = -1; + } + + if (saved_errno) + errno = saved_errno; + + if (close_err_gbe) + return -1; + + return 0; +} + static const char * getnvmprogname(void) { |
