about summary refs log tree commit diff
path: root/test-skeleton.c
diff options
context:
space:
mode:
Diffstat (limited to 'test-skeleton.c')
-rw-r--r--test-skeleton.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/test-skeleton.c b/test-skeleton.c
index 913a335782..65a3818309 100644
--- a/test-skeleton.c
+++ b/test-skeleton.c
@@ -33,6 +33,7 @@
 #include <sys/wait.h>
 #include <sys/param.h>
 #include <time.h>
+#include <stdarg.h>
 
 /* The test function is normally called `do_test' and it is called
    with argc and argv as the arguments.  We nevertheless provide the
@@ -115,6 +116,20 @@ xrealloc (void *p, size_t n)
   return result;
 }
 
+/* Call asprintf with error checking.  */
+__attribute__ ((always_inline, format (printf, 1, 2)))
+static __inline__ char *
+xasprintf (const char *format, ...)
+{
+  char *result;
+  if (asprintf (&result, format, __builtin_va_arg_pack ()) < 0)
+    {
+      printf ("error: asprintf: %m\n");
+      exit (1);
+    }
+  return result;
+}
+
 /* Write a message to standard output.  Can be used in signal
    handlers.  */
 static void