From b6656786caa1b5247e251e63d15f3173bcf3d26f Mon Sep 17 00:00:00 2001 From: pommicket Date: Tue, 25 Feb 2025 15:15:10 -0500 Subject: logging --- log.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'log.c') diff --git a/log.c b/log.c index a4e585d..2e0aecb 100644 --- a/log.c +++ b/log.c @@ -1,6 +1,7 @@ #include "log.h" #include #include +#include static FILE *log_file = NULL; @@ -59,6 +60,19 @@ void log_error(const char *fmt, ...) { va_end(args); } +void log_perror(const char *fmt, ...) { + int err = errno; + va_list args; + va_start(args, fmt); + char *prefix = va_sprintf(fmt, args); + va_end(args); + char error[64]; + *error = '\0'; + strerror_r(err, error, sizeof error); + log_error("%s: %s", prefix, error); + free(prefix); +} + void log_warning(const char *fmt, ...) { va_list args; va_start(args, fmt); -- cgit v1.2.3