Factor out usage_exit into into tools/common.h

This commit is contained in:
Rangi
2021-09-21 17:37:43 -04:00
parent 2691c9f5c8
commit be7a5e09b5
7 changed files with 48 additions and 58 deletions

View File

@@ -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)