]> git.sur5r.net Git - i3/i3/blobdiff - libi3/safewrappers.c
introduce sasprintf() in libi3, use it everywhere
[i3/i3] / libi3 / safewrappers.c
index 82311fe3a2115bb96c956e514af3dd73415e37e6..2403578dc41da66bd32ce17f4a7d4f455255ab96 100644 (file)
@@ -10,6 +10,8 @@
  */
 #include <string.h>
 #include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
 #include <err.h>
 
 
@@ -45,3 +47,14 @@ char *sstrdup(const char *str) {
         err(EXIT_FAILURE, "strdup()");
     return result;
 }
+
+int sasprintf(char **strp, const char *fmt, ...) {
+    va_list args;
+    int result;
+
+    va_start(args, fmt);
+    if ((result = vasprintf(strp, fmt, args)) == -1)
+        err(EXIT_FAILURE, "asprintf(%s)", fmt);
+    va_end(args);
+    return result;
+}