mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-20 05:36:23 +02:00
util/nvmutil: tidy up err()
Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+23
-25
@@ -430,8 +430,8 @@ static int try_err(int loop_err, int errval);
|
|||||||
/*
|
/*
|
||||||
* Error handling and cleanup
|
* Error handling and cleanup
|
||||||
*/
|
*/
|
||||||
static int close_files(void);
|
|
||||||
static void err(int nvm_errval, const char *msg, ...);
|
static void err(int nvm_errval, const char *msg, ...);
|
||||||
|
static int close_files(void);
|
||||||
static const char *getnvmprogname(void);
|
static const char *getnvmprogname(void);
|
||||||
static void usage(int usage_exit);
|
static void usage(int usage_exit);
|
||||||
|
|
||||||
@@ -2252,6 +2252,28 @@ try_err(int loop_err, int errval)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
err(int nvm_errval, const char *msg, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
if (errno == 0)
|
||||||
|
errno = nvm_errval;
|
||||||
|
|
||||||
|
(void)close_files();
|
||||||
|
|
||||||
|
fprintf(stderr, "%s: ", getnvmprogname());
|
||||||
|
|
||||||
|
va_start(args, msg);
|
||||||
|
vfprintf(stderr, msg, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
fprintf(stderr, ": %s", strerror(errno));
|
||||||
|
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
close_files(void)
|
close_files(void)
|
||||||
{
|
{
|
||||||
@@ -2273,30 +2295,6 @@ close_files(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
err(int nvm_errval, const char *msg, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
|
|
||||||
if (errno < 0)
|
|
||||||
errno = ECANCELED;
|
|
||||||
if (!errno)
|
|
||||||
errno = nvm_errval;
|
|
||||||
|
|
||||||
(void)close_files();
|
|
||||||
|
|
||||||
fprintf(stderr, "%s: ", getnvmprogname());
|
|
||||||
|
|
||||||
va_start(args, msg);
|
|
||||||
vfprintf(stderr, msg, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
fprintf(stderr, ": %s", strerror(errno));
|
|
||||||
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
getnvmprogname(void)
|
getnvmprogname(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user