#include #include #include #include "logerr.h" static FILE * STREAM = NULL; void 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"); } if (vfprintf(stream, format, args) < 0) { perror(__FILE__ ":vlogerr(): vfprintf() < 0"); } 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; }