diff options
Diffstat (limited to 'src/logerr.c')
-rw-r--r-- | src/logerr.c | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/src/logerr.c b/src/logerr.c index fac87f0..2d5c340 100644 --- a/src/logerr.c +++ b/src/logerr.c @@ -1,34 +1,72 @@ -#include "config.h" +#include <s.h> #include <stdarg.h> #include <stdio.h> -#include <stdlib.h> #include "logerr.h" +static FILE * +STREAM = NULL; + + + void -vlogerr( +vflogerrf( const char *const file, const char *const function, const int lineno, FILE *restrict stream, const char *restrict format, - ... + va_list args ) { if (fprintf(stream, "%s:%s:%d: ", file, function, lineno) < 0) { perror(__FILE__ ":vlogerr(): fprintf() < 0"); } - va_list args; - va_start(args, format); if (vfprintf(stream, format, args) < 0) { perror(__FILE__ ":vlogerr(): vfprintf() < 0"); } - va_end(args); if (fprintf(stream, "\n") < 0) { perror(__FILE__ ":vlogerr(): fprintf() < 0"); } } + +void +flogerrf( + const char *const file, + const char *const function, + const int lineno, + FILE *restrict stream, + const char *restrict format, + ... +) { + va_list args; + va_start(args, format); + vflogerrf(file, function, lineno, stream, format, args); + va_end(args); +} + +void +logerrf( + const char *const file, + const char *const function, + const int lineno, + const char *restrict format, + ... +) { + if (STREAM == NULL) { + STREAM = stderr; + } + va_list args; + va_start(args, format); + vflogerrf(file, function, lineno, STREAM, format, args); + va_end(args); +} + +void +logerr_set_stream(FILE *stream) { + STREAM = stream; +} |