diff options
author | Rangi <remy.oukaour+rangi42@gmail.com> | 2021-09-21 17:37:43 -0400 |
---|---|---|
committer | Rangi <remy.oukaour+rangi42@gmail.com> | 2021-09-21 17:37:43 -0400 |
commit | be7a5e09b5e54676a9c239682707331be1229828 (patch) | |
tree | 879d9bde5445a2842d7d38538b3d181d70b701f1 /tools/common.h | |
parent | 2691c9f5c8f866a2af802a119a565c743c05fceb (diff) |
Factor out usage_exit into into tools/common.h
Diffstat (limited to 'tools/common.h')
-rw-r--r-- | tools/common.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/tools/common.h b/tools/common.h index 2010e9e9d..506b483b9 100644 --- a/tools/common.h +++ b/tools/common.h @@ -11,7 +11,19 @@ #include <unistd.h> #include <getopt.h> -#define error_exit(...) exit((fprintf(stderr, __VA_ARGS__), 1)) +#ifndef PROGRAM_NAME +#error Define PROGRAM_NAME before including common.h! +#endif +#ifndef USAGE_OPTS +#error Define USAGE_OPTS before including common.h! +#endif + +#define error_exit(...) exit((fprintf(stderr, PROGRAM_NAME ": " __VA_ARGS__), 1)) + +void usage_exit(int status) { + fprintf(stderr, "Usage: " PROGRAM_NAME " " USAGE_OPTS "\n"); + exit(status); +} int getopt_long_index; #define getopt_long(argc, argv, optstring, longopts) getopt_long(argc, argv, optstring, longopts, &getopt_long_index) |