summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/macros.h32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/macros.h b/src/macros.h
index 091af77..f78d1a4 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -20,16 +20,28 @@
#include <stdio.h>
#include <stdlib.h>
-#define fatal_if(_cond, _fmt, ...) \
- if (_cond) { \
- fprintf(stderr, "Fatal error: " _fmt "\n", ##__VA_ARGS__); \
- exit(EXIT_FAILURE); \
- }
-
-#define warn_if(_cond, _fmt, ...) \
- if (_cond) { \
- fprintf(stderr, "Warning: " _fmt "\n", ##__VA_ARGS__); \
- }
+#define fatal(_fmt, ...) \
+ do { \
+ fprintf(stderr, "Fatal error: " _fmt "\n", ##__VA_ARGS__); \
+ exit(EXIT_FAILURE); \
+ } while (0)
+
+#define fatal_if(_cond, _fmt, ...) \
+ do { \
+ if (_cond) \
+ fatal(_fmt, ##__VA_ARGS__); \
+ } while (0)
+
+#define warn(_fmt, ...) \
+ do { \
+ fprintf(stderr, "Warning: " _fmt "\n", ##__VA_ARGS__); \
+ } while (0)
+
+#define warn_if(_cond, _fmt, ...) \
+ do { \
+ if (_cond) \
+ warn(_fmt, ##__VA_ARGS__); \
+ } while (0)
#define NELEMS(_a) \
(sizeof(_a) / sizeof(_a[0]))
© All Rights Reserved