summaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'util.h')
-rw-r--r--util.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/util.h b/util.h
index ccfdf4b124337..bc3d223fa6e3e 100644
--- a/util.h
+++ b/util.h
@@ -27,13 +27,20 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-static inline void __attribute__((noreturn)) die(const char *str, ...)
+#ifdef __GNUC__
+static inline void
+__attribute__((noreturn)) __attribute__((format (printf, 1, 2)))
+die(const char *str, ...)
+#else
+static inline void die(const char *str, ...)
+#endif
{
va_list ap;
va_start(ap, str);
fprintf(stderr, "FATAL ERROR: ");
vfprintf(stderr, str, ap);
+ va_end(ap);
exit(1);
}
@@ -52,12 +59,19 @@ static inline void *xrealloc(void *p, size_t len)
void *new = realloc(p, len);
if (!new)
- die("realloc() failed (len=%d)\n", len);
+ die("realloc() failed (len=%zd)\n", len);
return new;
}
extern char *xstrdup(const char *s);
+
+#ifdef __GNUC__
+extern int __attribute__((format (printf, 2, 3)))
+xasprintf(char **strp, const char *fmt, ...);
+#else
+extern int xasprintf(char **strp, const char *fmt, ...);
+#endif
extern char *join_path(const char *path, const char *name);
/**