]> xenbits.xensource.com Git - people/liuw/xtf.git/commitdiff
Introduce snprintf() and give vsnprintf() an appropriate __printf() attribute
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 28 Apr 2016 12:04:51 +0000 (13:04 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 28 Apr 2016 12:04:59 +0000 (13:04 +0100)
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
include/xtf/libc.h

index 65ea6c8ed40daea73c2916f3d8665aba3f028ffe..cf0aaf41394020318d44fe4f2a64892d2b25f9d1 100644 (file)
@@ -2,6 +2,7 @@
 #define XTF_LIBC_H
 
 #include <xtf/types.h>
+#include <xtf/compiler.h>
 
 /*
  * 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 */