summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
index d83e40c..88aee89 100644
--- a/src/util.h
+++ b/src/util.h
@@ -46,6 +46,14 @@ typedef unsigned char BOOL;
} \
} while (0)
+#define SAFE_CALLOC(TYPE, VAR, LEN, CLEAN) do { \
+ VAR = calloc((LEN), sizeof (TYPE)); \
+ if (VAR == NULL) { \
+ fleprintf0("Fail to calloc\n"); \
+ { CLEAN }; \
+ } \
+ } while (0)
+
#define SAFE_REALLOC(TYPE, VAR, LEN, CLEAN) do { \
TYPE *macro_new_var = \
realloc(VAR, sizeof (TYPE) * (LEN)); \
@@ -57,6 +65,16 @@ typedef unsigned char BOOL;
} \
} while (0)
+/* very convenient macro */
+#define PASTER2(X, Y, Z) X ## Y ## Z
+#define PASTER(X, Y, Z) PASTER2(X, Y, Z)
+
BOOL read_entire_file(const char *file_name, char **str, NUM *len);
+/* The purpose of this macro is to be used at the end of a macro
+ defining a function, so that we can add a semicolon when calling
+ that macro. I was using the keyword _Static_assert, but that
+ requires C11, which sounds kind of absurd to me. */
+#define MY_Static_MES(MES) struct STATIC_STRUCT_s
+
#endif