From ccc018887c443bf06482632d41798ec914a1df53 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sun, 22 Mar 2026 22:15:46 +0100 Subject: Added fprintf_logerr() and defined mfprintf() --- FICS/maxxes-utils.c | 25 +++++++++++++++++++++++++ FICS/maxxes-utils.h | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/FICS/maxxes-utils.c b/FICS/maxxes-utils.c index 987be47..344a4fb 100644 --- a/FICS/maxxes-utils.c +++ b/FICS/maxxes-utils.c @@ -12,6 +12,31 @@ #include "maxxes-utils.h" +void +fprintf_logerr(const char *file, const long int line, + FILE *fp, const char *format, ...) +{ + int ret; + va_list ap; + + if (fp == NULL) { + warnx("%s:%ld: error: invalid argument (null pointer)", + file, line); + return; + } else if (fp == stdin || fp == stdout || fp == stderr) { + warnx("%s:%ld: error: invalid stream (stdin, stdout or stderr)", + file, line); + return; + } + + va_start(ap, format); + ret = vfprintf(fp, format, ap); + va_end(ap); + + if (ret < 0) + warnx("%s:%ld: warning: vfprintf() error", file, line); +} + bool is_too_long(const int p_ret, const size_t p_maxlen) { diff --git a/FICS/maxxes-utils.h b/FICS/maxxes-utils.h index 2e2c723..75380e8 100644 --- a/FICS/maxxes-utils.h +++ b/FICS/maxxes-utils.h @@ -6,6 +6,8 @@ #include "common.h" +#define mfprintf(p_fp, ...) \ + fprintf_logerr(__FILE__, __LINE__, (p_fp), __VA_ARGS__) #define msnprintf(p_str, p_size, ...) \ snprintf_trunc_chk(__FILE__, __LINE__, (p_str), (p_size), __VA_ARGS__) #define mstrlcpy(p_dst, p_src, p_dstsize) \ @@ -14,6 +16,9 @@ strlcat_trunc_chk((p_dst), (p_src), (p_dstsize), __FILE__, __LINE__) __FICS_BEGIN_DECLS +void fprintf_logerr(const char *file, const long int line, + FILE *, const char *format, ...) PRINTFLIKE(4); + bool is_too_long(const int, const size_t); void snprintf_trunc_chk(const char *file, const long int line, -- cgit v1.2.3