summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2021-09-25 16:55:53 -0700
committerVito Caputo <vcaputo@pengaru.com>2021-09-26 18:05:06 -0700
commita3fe7db45439de1f022e6389f55d59198865bde6 (patch)
treecf044a014ddbaedf6048b91a5325228933722e9b
parenta59229b6d83057650b320e44ad1f2e74f6fceac7 (diff)
macros: unconditional variants of {warn,fatal}_if()
-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