diff options
author | JSDurand <mmemmew@gmail.com> | 2022-01-21 21:53:50 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2022-01-21 21:53:50 +0800 |
commit | 53865aad225ffbe5cf3c42736e5a2095092f9fff (patch) | |
tree | 697ecbee7fa69ae8c58a0ec2f69cdf84d7cd313f /src/util.h | |
parent | 5730d6c04258e192195bfbbbed76d68fd78ed458 (diff) |
temporary save point
Just to save some work.
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -28,11 +28,33 @@ typedef unsigned char BOOL; #define UH_ATTR __attribute__((__unused__, __hot__)) #define UHP_ATTR __attribute__((__unused__, __hot__, __pure__)) +/* For convenient declarations */ +#define CC_MOD(X) const X const +#define CCR_MOD(X) const X const restrict #define eprintf(...) fprintf(stderr, __VA_ARGS__) #define fleprintf0(M) eprintf("%s:%d, " M, __FILE__, __LINE__) #define fleprintf(M, ...) eprintf("%s:%d, " M, __FILE__, __LINE__, __VA_ARGS__) +#define SAFE_MALLOC(TYPE, VAR, LEN, CLEAN) do { \ + VAR = malloc(sizeof (TYPE) * (LEN)); \ + if (VAR == NULL) { \ + fleprintf0("Fail to malloc\n"); \ + { CLEAN }; \ + } \ + } while (0) + +#define SAFE_REALLOC(TYPE, VAR, LEN, CLEAN) do { \ + TYPE *macro_new_var = \ + realloc(VAR, sizeof (TYPE) * (LEN)); \ + if (macro_new_var == NULL) { \ + fleprintf0("Fail to realloc\n"); \ + { CLEAN }; \ + } else { \ + VAR = macro_new_var; \ + } \ + } while (0) + BOOL read_entire_file(const char *file_name, char **str, NUM *len); #endif |