aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/maxxes-utils.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-04-13 16:39:59 +0200
committerMarkus Uhlin <markus@nifty-networks.net>2024-04-13 16:39:59 +0200
commitebdec4bcefe286c6b322bf26aa48b32aac6b57e5 (patch)
tree4ec6872b70ee04e924c12d73d8f6a3d4fae1d26f /FICS/maxxes-utils.c
parent95107ed63ef4d41e6a41cb8ea2375798c9248a58 (diff)
My utils
Diffstat (limited to 'FICS/maxxes-utils.c')
-rw-r--r--FICS/maxxes-utils.c46
1 files changed, 46 insertions, 0 deletions
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 <maxxe@rpblc.net>
+// SPDX-License-Identifier: ISC
+
+#include <err.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+#if __linux__
+#include <bsd/string.h>
+#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);
+}