aboutsummaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'util.h')
-rw-r--r--util.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/util.h b/util.h
index 1fa78eb..0fb60fe 100644
--- a/util.h
+++ b/util.h
@@ -1,3 +1,6 @@
+#ifndef _UTIL_H
+#define _UTIL_H
+
/*
* Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.
*
@@ -17,4 +20,36 @@
* USA
*/
+static inline void __attribute__((noreturn)) die(char * str, ...)
+{
+ va_list ap;
+
+ va_start(ap, str);
+ fprintf(stderr, "FATAL ERROR: ");
+ vfprintf(stderr, str, ap);
+ exit(1);
+}
+
+static inline void *xmalloc(size_t len)
+{
+ void *new = malloc(len);
+
+ if (!new)
+ die("malloc() failed\n");
+
+ return new;
+}
+
+static inline void *xrealloc(void *p, size_t len)
+{
+ void *new = realloc(p, len);
+
+ if (!new)
+ die("realloc() failed (len=%d)\n", len);
+
+ return new;
+}
+
extern char *xstrdup(const char *s);
+
+#endif /* _UTIL_H */