From c91d1a6b1791f4dfb14a6c502a834336bc761b4b Mon Sep 17 00:00:00 2001 From: rapperskull Date: Thu, 10 Nov 2022 21:24:40 +0100 Subject: [PATCH] Replace exit codes with EXIT_SUCCESS and EXIT_FAILURE. Change-Id: I6777420892629ea6705806ba624ffb200d395114 --- libsparse/append2simg.cpp | 24 ++++++++++++------------ libsparse/img2simg.cpp | 18 +++++++++--------- libsparse/simg2img.cpp | 12 ++++++------ libsparse/simg2simg.cpp | 20 ++++++++++---------- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/libsparse/append2simg.cpp b/libsparse/append2simg.cpp index 99f433981..d3a43a885 100644 --- a/libsparse/append2simg.cpp +++ b/libsparse/append2simg.cpp @@ -64,60 +64,60 @@ int main(int argc, char* argv[]) { input_path = argv[2]; } else { usage(); - exit(-1); + exit(EXIT_FAILURE); } ret = asprintf(&tmp_path, "%s.append2simg", output_path); if (ret < 0) { fprintf(stderr, "Couldn't allocate filename\n"); - exit(-1); + exit(EXIT_FAILURE); } output = open(output_path, O_RDWR | O_BINARY); if (output < 0) { fprintf(stderr, "Couldn't open output file (%s)\n", strerror(errno)); - exit(-1); + exit(EXIT_FAILURE); } sparse_output = sparse_file_import_auto(output, false, true); if (!sparse_output) { fprintf(stderr, "Couldn't import output file\n"); - exit(-1); + exit(EXIT_FAILURE); } input = open(input_path, O_RDONLY | O_BINARY); if (input < 0) { fprintf(stderr, "Couldn't open input file (%s)\n", strerror(errno)); - exit(-1); + exit(EXIT_FAILURE); } input_len = lseek64(input, 0, SEEK_END); if (input_len < 0) { fprintf(stderr, "Couldn't get input file length (%s)\n", strerror(errno)); - exit(-1); + exit(EXIT_FAILURE); } else if (input_len % sparse_output->block_size) { fprintf(stderr, "Input file is not a multiple of the output file's block size"); - exit(-1); + exit(EXIT_FAILURE); } lseek64(input, 0, SEEK_SET); output_block = sparse_output->len / sparse_output->block_size; if (sparse_file_add_fd(sparse_output, input, 0, input_len, output_block) < 0) { fprintf(stderr, "Couldn't add input file\n"); - exit(-1); + exit(EXIT_FAILURE); } sparse_output->len += input_len; tmp_fd = open(tmp_path, O_WRONLY | O_CREAT | O_BINARY, 0664); if (tmp_fd < 0) { fprintf(stderr, "Couldn't open temporary file (%s)\n", strerror(errno)); - exit(-1); + exit(EXIT_FAILURE); } lseek64(output, 0, SEEK_SET); if (sparse_file_write(sparse_output, tmp_fd, false, true, false) < 0) { fprintf(stderr, "Failed to write sparse file\n"); - exit(-1); + exit(EXIT_FAILURE); } sparse_file_destroy(sparse_output); @@ -128,10 +128,10 @@ int main(int argc, char* argv[]) { ret = rename(tmp_path, output_path); if (ret < 0) { fprintf(stderr, "Failed to rename temporary file (%s)\n", strerror(errno)); - exit(-1); + exit(EXIT_FAILURE); } free(tmp_path); - exit(0); + exit(EXIT_SUCCESS); } diff --git a/libsparse/img2simg.cpp b/libsparse/img2simg.cpp index 51580f706..c390506af 100644 --- a/libsparse/img2simg.cpp +++ b/libsparse/img2simg.cpp @@ -61,14 +61,14 @@ int main(int argc, char* argv[]) { break; default: usage(); - exit(-1); + exit(EXIT_FAILURE); } } extra = argc - optind; if (extra < 2 || extra > 3) { usage(); - exit(-1); + exit(EXIT_FAILURE); } if (extra == 3) { @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) { if (block_size < 1024 || block_size % 4 != 0) { usage(); - exit(-1); + exit(EXIT_FAILURE); } arg_in = argv[optind]; @@ -87,7 +87,7 @@ int main(int argc, char* argv[]) { in = open(arg_in, O_RDONLY | O_BINARY); if (in < 0) { fprintf(stderr, "Cannot open input file %s\n", arg_in); - exit(-1); + exit(EXIT_FAILURE); } } @@ -98,7 +98,7 @@ int main(int argc, char* argv[]) { out = open(arg_out, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0664); if (out < 0) { fprintf(stderr, "Cannot open output file %s\n", arg_out); - exit(-1); + exit(EXIT_FAILURE); } } @@ -108,24 +108,24 @@ int main(int argc, char* argv[]) { s = sparse_file_new(block_size, len); if (!s) { fprintf(stderr, "Failed to create sparse file\n"); - exit(-1); + exit(EXIT_FAILURE); } sparse_file_verbose(s); ret = sparse_file_read(s, in, mode, false); if (ret) { fprintf(stderr, "Failed to read file\n"); - exit(-1); + exit(EXIT_FAILURE); } ret = sparse_file_write(s, out, false, true, false); if (ret) { fprintf(stderr, "Failed to write sparse file\n"); - exit(-1); + exit(EXIT_FAILURE); } close(in); close(out); - exit(0); + exit(EXIT_SUCCESS); } diff --git a/libsparse/simg2img.cpp b/libsparse/simg2img.cpp index 8ba5f6989..2301a83d0 100644 --- a/libsparse/simg2img.cpp +++ b/libsparse/simg2img.cpp @@ -41,13 +41,13 @@ int main(int argc, char* argv[]) { if (argc < 3) { usage(); - exit(-1); + exit(EXIT_FAILURE); } out = open(argv[argc - 1], O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0664); if (out < 0) { fprintf(stderr, "Cannot open output file %s\n", argv[argc - 1]); - exit(-1); + exit(EXIT_FAILURE); } for (i = 1; i < argc - 1; i++) { @@ -57,14 +57,14 @@ int main(int argc, char* argv[]) { in = open(argv[i], O_RDONLY | O_BINARY); if (in < 0) { fprintf(stderr, "Cannot open input file %s\n", argv[i]); - exit(-1); + exit(EXIT_FAILURE); } } s = sparse_file_import(in, true, false); if (!s) { fprintf(stderr, "Failed to read sparse file\n"); - exit(-1); + exit(EXIT_FAILURE); } if (lseek(out, 0, SEEK_SET) == -1) { @@ -74,7 +74,7 @@ int main(int argc, char* argv[]) { if (sparse_file_write(s, out, false, false, false) < 0) { fprintf(stderr, "Cannot write output file\n"); - exit(-1); + exit(EXIT_FAILURE); } sparse_file_destroy(s); close(in); @@ -82,5 +82,5 @@ int main(int argc, char* argv[]) { close(out); - exit(0); + exit(EXIT_SUCCESS); } diff --git a/libsparse/simg2simg.cpp b/libsparse/simg2simg.cpp index 138173b3d..72483c1fe 100644 --- a/libsparse/simg2simg.cpp +++ b/libsparse/simg2simg.cpp @@ -49,7 +49,7 @@ int main(int argc, char* argv[]) { if (argc != 4) { usage(); - exit(-1); + exit(EXIT_FAILURE); } max_size = atoll(argv[3]); @@ -57,55 +57,55 @@ int main(int argc, char* argv[]) { in = open(argv[1], O_RDONLY | O_BINARY); if (in < 0) { fprintf(stderr, "Cannot open input file %s\n", argv[1]); - exit(-1); + exit(EXIT_FAILURE); } s = sparse_file_import(in, true, false); if (!s) { fprintf(stderr, "Failed to import sparse file\n"); - exit(-1); + exit(EXIT_FAILURE); } files = sparse_file_resparse(s, max_size, nullptr, 0); if (files < 0) { fprintf(stderr, "Failed to resparse\n"); - exit(-1); + exit(EXIT_FAILURE); } out_s = (struct sparse_file**)calloc(sizeof(struct sparse_file*), files); if (!out_s) { fprintf(stderr, "Failed to allocate sparse file array\n"); - exit(-1); + exit(EXIT_FAILURE); } files = sparse_file_resparse(s, max_size, out_s, files); if (files < 0) { fprintf(stderr, "Failed to resparse\n"); - exit(-1); + exit(EXIT_FAILURE); } for (i = 0; i < files; i++) { ret = snprintf(filename, sizeof(filename), "%s.%d", argv[2], i); if (ret >= (int)sizeof(filename)) { fprintf(stderr, "Filename too long\n"); - exit(-1); + exit(EXIT_FAILURE); } out = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0664); if (out < 0) { fprintf(stderr, "Cannot open output file %s\n", argv[2]); - exit(-1); + exit(EXIT_FAILURE); } ret = sparse_file_write(out_s[i], out, false, true, false); if (ret) { fprintf(stderr, "Failed to write sparse file\n"); - exit(-1); + exit(EXIT_FAILURE); } close(out); } close(in); - exit(0); + exit(EXIT_SUCCESS); }