From e2f1d2cc25bede1a2cc14934f53886d2b1e7294b Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Thu, 28 Apr 2016 13:04:51 +0100 Subject: [PATCH] Introduce snprintf() and give vsnprintf() an appropriate __printf() attribute Signed-off-by: Andrew Cooper --- include/xtf/libc.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/include/xtf/libc.h b/include/xtf/libc.h index 65ea6c8..cf0aaf4 100644 --- a/include/xtf/libc.h +++ b/include/xtf/libc.h @@ -2,6 +2,7 @@ #define XTF_LIBC_H #include +#include /* * Local declaration of bits of libc @@ -24,7 +25,21 @@ void *memset(void *s, int c, size_t n); void *memcpy(void *dst, const void *src, size_t n); int memcmp(const void *s1, const void *s2, size_t n); -int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); +int __printf(3, 0) + vsnprintf(char *buf, size_t size, const char *fmt, va_list args); + +static inline int __printf(3, 4) + snprintf(char *buf, size_t size, const char *fmt, ...) +{ + va_list args; + int rc; + + va_start(args, fmt); + rc = vsnprintf(buf, size, fmt, args); + va_end(args); + + return rc; +} #endif /* XTF_LIBC_H */ -- 2.39.5