summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-01-27 08:00:11 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-02-01 17:21:39 -0500
commit5ffa8c818120e35c89becd938d160235c069dd12 (patch)
treee4a1ce20a003e23618bd54f49cb4acf68aed70cd /src/shared/util.h
parent294929f8916ca37d89ccb1757868d22f8068c56b (diff)
Add a snprinf wrapper which checks that the buffer was big enough
If we scale our buffer to be wide enough for the format string, we should expect that the calculation was correct. char_array_0() invocations are removed, since snprintf nul-terminates the output in any case. A similar wrapper is used for strftime calls, but only in timedatectl.c.
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index ca0c2e5e3d..5312422134 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -481,6 +481,8 @@ cpu_set_t* cpu_set_malloc(unsigned *ncpus);
int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) _printf_(4,0);
int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) _printf_(4,5);
+#define xsprintf(buf, fmt, ...) assert_se((size_t) snprintf(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__) < ELEMENTSOF(buf))
+
int fd_columns(int fd);
unsigned columns(void);
int fd_lines(int fd);