From c3eee8e333866d92e5fd94ae83cef618758c11bb Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Mon, 15 Sep 2025 18:50:32 +0200 Subject: FICS RPBLC v1.4.6 --- FICS/maxxes-utils.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 FICS/maxxes-utils.c (limited to 'FICS/maxxes-utils.c') diff --git a/FICS/maxxes-utils.c b/FICS/maxxes-utils.c new file mode 100644 index 0000000..7db8369 --- /dev/null +++ b/FICS/maxxes-utils.c @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2024 Markus Uhlin +// SPDX-License-Identifier: ISC + +#include +#include +#include +#include + +#if __linux__ +#include +#endif + +#include "maxxes-utils.h" + +void +snprintf_trunc_chk(const char *file, const long int line, + char *str, size_t size, const char *format, ...) +{ + int ret; + va_list ap; + + va_start(ap, format); + ret = vsnprintf(str, size, format, ap); + va_end(ap); + + if (ret < 0 || (size_t)ret >= size) + warnx("%s:%ld: warning: vsnprintf() truncated", file, line); +} + +void +strlcpy_trunc_chk(char *dst, const char *src, size_t dstsize, + const char *file, + const long int line) +{ + if (strlcpy(dst, src, dstsize) >= dstsize) + warnx("%s:%ld: warning: strlcpy() truncated", file, line); +} + +void +strlcat_trunc_chk(char *dst, const char *src, size_t dstsize, + const char *file, + const long int line) +{ + if (strlcat(dst, src, dstsize) >= dstsize) + warnx("%s:%ld: warning: strlcat() truncated", file, line); +} -- cgit v1.2.3