From bf61d93febc8791858c7634cb045c65d82d4ada3 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 19 Mar 2021 02:56:51 +0000 Subject: log: add die function This is useful if we want to provide a more specific error message than strerror can provide. Message-Id: <20210319025648.17925-5-hi@alyssa.is> Reviewed-by: Cole Helbling --- log.c | 10 ++++++++++ log.h | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/log.c b/log.c index cdfacd6..8a57105 100644 --- a/log.c +++ b/log.c @@ -62,6 +62,16 @@ void ilog(const char *fmt, ...) va_end(ap); } +void die(int eval, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + velog(fmt, ap); + va_end(ap); + + exit(eval); +} + void diee(int eval, const char *fmt, ...) { va_list ap; diff --git a/log.h b/log.h index 7b40e48..706d42f 100644 --- a/log.h +++ b/log.h @@ -11,20 +11,20 @@ enum verbosity { extern enum verbosity verbosity; +// Functions with an `e' suffix additionally print strerrno(errno). + // If opt is a character that matches a standard UCSPI command line // verbosity option, sets the verbosity appropriately and returns // true. Otherwise, returns false. _Bool set_verbosity(int opt); -// Log an error message, followed by strerrno(errno), then exit with -// status eval. +// Log an error message then exit with status eval. +_Noreturn void die(int eval, const char *fmt, ...); _Noreturn void diee(int eval, const char *fmt, ...); // Log an error message. void elog(const char *fmt, ...); void velog(const char *fmt, va_list args); - -// Log an error message, followed by strerror(errno). void veloge(const char *fmt, va_list args); // Log an informative message. -- cgit 1.4.1