diff options
Diffstat (limited to 'examples/utils.h')
| -rw-r--r-- | examples/utils.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/examples/utils.h b/examples/utils.h new file mode 100644 index 0000000..dc48a85 --- /dev/null +++ b/examples/utils.h | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | // examples/utils.h | ||
| 2 | |||
| 3 | #ifndef INCLUDED_UTILS_H | ||
| 4 | #define INCLUDED_UTILS_H | ||
| 5 | |||
| 6 | #include <stdlib.h> | ||
| 7 | #include <stdio.h> | ||
| 8 | |||
| 9 | #define CMMM__STRING_VIEW__STRIP_VENDOR | ||
| 10 | #define CMMM__STRING_VIEW__SHORT_NAMESPACE | ||
| 11 | #define CMMM__ARENA__STRIP_VENDOR | ||
| 12 | |||
| 13 | #include "cmmm/string-view.h" | ||
| 14 | #include "cmmm/arena.h" | ||
| 15 | |||
| 16 | #define NOP() do {} while (0) | ||
| 17 | |||
| 18 | #define UNUSED(EXP) ((void) EXP) | ||
| 19 | |||
| 20 | #define ARRAY_LENGTH(ARR) (sizeof (ARR)/sizeof (*(ARR))) | ||
| 21 | |||
| 22 | #ifndef NDEBUG | ||
| 23 | #include <assert.h> | ||
| 24 | #define ASSERT assert | ||
| 25 | #else | ||
| 26 | #define ASSERT(...) NOP () | ||
| 27 | #endif | ||
| 28 | |||
| 29 | #define STRINGIFY(ARG) #ARG | ||
| 30 | #define TO_STRING(ARG) STRINGIFY (ARG) | ||
| 31 | |||
| 32 | #ifndef NDEBUG | ||
| 33 | #define DEBUG(FMT, ...) \ | ||
| 34 | fprintf (stderr, __FILE__ ":" TO_STRING (__LINE__) ": %s: " FMT "\n", \ | ||
| 35 | __func__ __VA_OPT__ (,) __VA_ARGS__) | ||
| 36 | #define LOG(FMT, ...) \ | ||
| 37 | fprintf (stderr, __FILE__ ":" TO_STRING (__LINE__) ": %s: " FMT "\n", \ | ||
| 38 | __func__ __VA_OPT__ (,) __VA_ARGS__) | ||
| 39 | #else | ||
| 40 | #define DEBUG(...) NOP () | ||
| 41 | #define LOG(FMT, ...) \ | ||
| 42 | fprintf (stderr, FMT "\n", __VA_OPT__ (,) __VA_ARGS__) | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #define ERROR(FMT, ...) LOG ("error: " FMT __VA_OPT__ (,) __VA_ARGS__) | ||
| 46 | #define WARNING(FMT, ...) LOG ("warning: " FMT __VA_OPT__ (,) __VA_ARGS__) | ||
| 47 | #define NOTICE(FMT, ...) LOG ("notice: " FMT __VA_OPT__ (,) __VA_ARGS__) | ||
| 48 | #define INFO(FMT, ...) LOG ("info: " FMT __VA_OPT__ (,) __VA_ARGS__) | ||
| 49 | |||
| 50 | #ifndef NDEBUG | ||
| 51 | #define ASSERT_MSG(EXP, FMT, ...) do if (!(EXP)) { \ | ||
| 52 | DEBUG (FMT __VA_OPT__ (,) __VA_ARGS__); \ | ||
| 53 | exit (EXIT_FAILURE); \ | ||
| 54 | } while (0) | ||
| 55 | #else | ||
| 56 | #define ASSERT_MSG(EXP, FMT, ...) NOP () | ||
| 57 | #endif | ||
| 58 | |||
| 59 | struct cmmm__sv mmap_whole (int fd); | ||
| 60 | struct cmmm__sv read_until_eof (ARENA, int fd); | ||
| 61 | |||
| 62 | #endif // INCLUDED_UTILS_H | ||
| 63 | |||
| 64 | // examples/utils.c ends here | ||
