summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@beefcake.parabola.nu>2018-05-16 10:18:21 -0400
committerLuke Shumaker <lukeshu@beefcake.parabola.nu>2018-05-16 10:18:21 -0400
commit94ee3156b7a22b02f8b21e6db3fcdf7d1ad51d0e (patch)
tree8215a30b61f6cf7fef1f02849e1d1e7774c2d70a
parent4e10b004887054f361854428b75f66b32ed0e105 (diff)
errusage
-rw-r--r--src/cow-dedupe-range.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/cow-dedupe-range.c b/src/cow-dedupe-range.c
index 33d62b0..bffa8f1 100644
--- a/src/cow-dedupe-range.c
+++ b/src/cow-dedupe-range.c
@@ -7,12 +7,19 @@
#include <stdbool.h> /* for bool, true, false */
#include <stdint.h> /* for uint64_t */
#include <stdio.h> /* for printf(3gnu), fprintf(3p), stderr */
-#include <stdlib.h> /* for strtoll(3p), calloc(3p), free(3p) */
+#include <stdlib.h> /* for strtoll(3p), calloc(3p), free(3p), exit(3p), EXIT_SUCCESS */
#include <string.h> /* for strlen(3p) */
#include <unistd.h> /* for dup2(3p) */
#include "dedupe-range.h" /* for dedupe_range, struct range */
+#define EXIT_INVALIDARGUMENT 2
+#define errusage(format, ...) do { \
+ error(0, 0, format, ## __VA_ARGS__); \
+ fprintf(stderr, "Try '%s --help' for more information.\n", program_invocation_name); \
+ exit(EXIT_INVALIDARGUMENT); \
+} while(0)
+
bool atou64(const char *str, uint64_t *ret) {
assert(sizeof(uint64_t) <= sizeof(unsigned long long int));
if (!('0' <= str[0] && str[0] <= '9'))
@@ -59,24 +66,18 @@ int main(int argc, char *argv[]) {
break;
case 'h':
usage();
- return 0;
+ return EXIT_SUCCESS;
case '?':
fprintf(stderr, "Try '%s --help' for more information.\n", program_invocation_name);
- return 2;
+ return EXIT_INVALIDARGUMENT;
default:
assert(false);
}
}
- if (argc - optind < 5) {
- error(0, 0, "too few arguments");
- fprintf(stderr, "Try '%s --help' for more information.\n", program_invocation_name);
- return 2;
- }
- if ((argc - optind - 3) % 2 != 0) {
- error(0, 0, "wrong number of arguments");
- fprintf(stderr, "Try '%s --help' for more information.\n", program_invocation_name);
- return 2;
- }
+ if (argc - optind < 5)
+ errusage("too few arguments");
+ if ((argc - optind - 3) % 2 != 0)
+ errusage("wrong number of arguments");
struct range src;
src.filename = argv[optind];
@@ -97,5 +98,5 @@ int main(int argc, char *argv[]) {
dedupe_range(src, dsts);
free(dsts);
- return 0;
+ return EXIT_SUCCESS;
}