summaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@gnugeneration.com>2016-11-23 19:19:20 -0800
committerVito Caputo <vcaputo@gnugeneration.com>2016-11-23 19:19:20 -0800
commit5de227689402736235f6bdb932fa9ad5f939fcb8 (patch)
tree8356f205b7f698c42774cd47cc73f29044829427 /util.h
parente3d3c06aa5b47648c0ed145279d7950df42ad80d (diff)
util: put convenience helpers into util.[ch]
Also introduces get_ncpus(), in preparation for threaded rendering.
Diffstat (limited to 'util.h')
-rw-r--r--util.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..c82b623
--- /dev/null
+++ b/util.h
@@ -0,0 +1,26 @@
+#ifndef _UTIL_H
+#define _UTIL_H
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define exit_if(_cond, _fmt, ...) \
+ if (_cond) { \
+ fprintf(stderr, "Fatal error: " _fmt "\n", ##__VA_ARGS__); \
+ exit(EXIT_FAILURE); \
+ }
+
+#define pexit_if(_cond, _fmt, ...) \
+ exit_if(_cond, _fmt ": %s", ##__VA_ARGS__, strerror(errno))
+
+#define nelems(_array) \
+ (sizeof(_array) / sizeof(_array[0]))
+
+#define cstrlen(_str) \
+ (sizeof(_str) - 1)
+
+unsigned get_ncpus(void);
+
+#endif /* _UTIL_H */
© All Rights Reserved