commit 30662c5b3c8fe5dcd7a416163396e5a4e08cb2cb
parent a0dcf1a108208ead97c12fb1a78f5ae6cb39906c
Author: Wilson Gheen <wilson@wilsonrgheen.com>
Date: Tue, 17 Jan 2023 15:50:30 -0600
Use EXIT_... macros instead of numbers
Diffstat:
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/photomosaics.c b/photomosaics.c
@@ -13,10 +13,10 @@
#include <unistd.h>
#include <MagickCore/MagickCore.h>
-#define DIE(rc, fmt, ...) { fprintf(stderr, "FATAL: "fmt"\n", __VA_ARGS__); exit(rc); }
+#define DIE(fmt, ...) { fprintf(stderr, "FATAL: "fmt"\n", __VA_ARGS__); exit(EXIT_FAILURE); }
#define WARN(fmt, ...) { fprintf(stderr, "WARN: " fmt"\n", __VA_ARGS__); }
#define assert_error(expression, s) if(!expression) { perror(s); abort(); }
-#define assert_call_succeeds(exit_code, s) if(exit_code != 0) { perror(s); abort(); }
+#define assert_call_succeeds(exit_code, s) if(exit_code != EXIT_SUCCESS) { perror(s); abort(); }
typedef struct {
unsigned int r, g, b;
@@ -429,26 +429,26 @@ int main(int argc, char **argv) {
usage(argv[0]);
return 0;
case 'i':
- if(slen(optarg, max_fn_len) == max_fn_len) DIE(2, "Argument \"%s\" to option -i should be less than %zu characters.", optarg, max_fn_len)
+ if(slen(optarg, max_fn_len) == max_fn_len) DIE("Argument \"%s\" to option -i should be less than %zu characters.", optarg, max_fn_len)
strncat(input_img_filename, optarg, max_fn_len - 1);
break;
case 'l':
if(!parse_ulong(optarg, &length))
- DIE(2, "Argument \"%s\" to option -l could not be parsed to an unsigned long int.", optarg);
+ DIE("Argument \"%s\" to option -l could not be parsed to an unsigned long int.", optarg);
break;
case 'o':
- if(slen(optarg, max_fn_len) == max_fn_len) DIE(2, "Argument \"%s\" to option -o should be less than %zu characters.", optarg, max_fn_len)
+ if(slen(optarg, max_fn_len) == max_fn_len) DIE("Argument \"%s\" to option -o should be less than %zu characters.", optarg, max_fn_len)
strncat(output_img_filename, optarg, max_fn_len - 1);
break;
case 'w':
if(!parse_ulong(optarg, &width))
- DIE(2, "Argument \"%s\" to option -w could not be parsed to an unsigned long int.", optarg);
+ DIE("Argument \"%s\" to option -w could not be parsed to an unsigned long int.", optarg);
break;
}
}
- if(slen(input_img_filename, max_fn_len) < 1) DIE(2, "No input image specified.%s", "");
- if(slen(output_img_filename, max_fn_len) < 1) DIE(2, "No output image specified.%s", "");
+ if(slen(input_img_filename, max_fn_len) < 1) DIE("No input image specified.%s", "");
+ if(slen(output_img_filename, max_fn_len) < 1) DIE("No output image specified.%s", "");
MagickCoreGenesis(*argv, MagickTrue);
exception = AcquireExceptionInfo();
@@ -459,7 +459,7 @@ int main(int argc, char **argv) {
if(exception->severity != UndefinedException)
CatchException(exception);
if(!input_img)
- DIE(1, "Input image %s could not be read.", input_img_filename);
+ DIE("Input image %s could not be read.", input_img_filename);
output_img = photomosaic(input_img, width, length, exception);
@@ -512,5 +512,5 @@ int main(int argc, char **argv) {
DestroyImageInfo(image_info);
DestroyExceptionInfo(exception);
MagickCoreTerminus();
- return 0;
+ return EXIT_SUCCESS;
}