Merge "Replace exit codes with EXIT_SUCCESS and EXIT_FAILURE."

This commit is contained in:
Treehugger Robot 2022-11-11 17:37:25 +00:00 committed by Gerrit Code Review
commit 1dcc32555e
4 changed files with 37 additions and 37 deletions

View file

@ -64,60 +64,60 @@ int main(int argc, char* argv[]) {
input_path = argv[2]; input_path = argv[2];
} else { } else {
usage(); usage();
exit(-1); exit(EXIT_FAILURE);
} }
ret = asprintf(&tmp_path, "%s.append2simg", output_path); ret = asprintf(&tmp_path, "%s.append2simg", output_path);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "Couldn't allocate filename\n"); fprintf(stderr, "Couldn't allocate filename\n");
exit(-1); exit(EXIT_FAILURE);
} }
output = open(output_path, O_RDWR | O_BINARY); output = open(output_path, O_RDWR | O_BINARY);
if (output < 0) { if (output < 0) {
fprintf(stderr, "Couldn't open output file (%s)\n", strerror(errno)); 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); sparse_output = sparse_file_import_auto(output, false, true);
if (!sparse_output) { if (!sparse_output) {
fprintf(stderr, "Couldn't import output file\n"); fprintf(stderr, "Couldn't import output file\n");
exit(-1); exit(EXIT_FAILURE);
} }
input = open(input_path, O_RDONLY | O_BINARY); input = open(input_path, O_RDONLY | O_BINARY);
if (input < 0) { if (input < 0) {
fprintf(stderr, "Couldn't open input file (%s)\n", strerror(errno)); fprintf(stderr, "Couldn't open input file (%s)\n", strerror(errno));
exit(-1); exit(EXIT_FAILURE);
} }
input_len = lseek64(input, 0, SEEK_END); input_len = lseek64(input, 0, SEEK_END);
if (input_len < 0) { if (input_len < 0) {
fprintf(stderr, "Couldn't get input file length (%s)\n", strerror(errno)); 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) { } else if (input_len % sparse_output->block_size) {
fprintf(stderr, "Input file is not a multiple of the output file's 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); lseek64(input, 0, SEEK_SET);
output_block = sparse_output->len / sparse_output->block_size; output_block = sparse_output->len / sparse_output->block_size;
if (sparse_file_add_fd(sparse_output, input, 0, input_len, output_block) < 0) { if (sparse_file_add_fd(sparse_output, input, 0, input_len, output_block) < 0) {
fprintf(stderr, "Couldn't add input file\n"); fprintf(stderr, "Couldn't add input file\n");
exit(-1); exit(EXIT_FAILURE);
} }
sparse_output->len += input_len; sparse_output->len += input_len;
tmp_fd = open(tmp_path, O_WRONLY | O_CREAT | O_BINARY, 0664); tmp_fd = open(tmp_path, O_WRONLY | O_CREAT | O_BINARY, 0664);
if (tmp_fd < 0) { if (tmp_fd < 0) {
fprintf(stderr, "Couldn't open temporary file (%s)\n", strerror(errno)); fprintf(stderr, "Couldn't open temporary file (%s)\n", strerror(errno));
exit(-1); exit(EXIT_FAILURE);
} }
lseek64(output, 0, SEEK_SET); lseek64(output, 0, SEEK_SET);
if (sparse_file_write(sparse_output, tmp_fd, false, true, false) < 0) { if (sparse_file_write(sparse_output, tmp_fd, false, true, false) < 0) {
fprintf(stderr, "Failed to write sparse file\n"); fprintf(stderr, "Failed to write sparse file\n");
exit(-1); exit(EXIT_FAILURE);
} }
sparse_file_destroy(sparse_output); sparse_file_destroy(sparse_output);
@ -128,10 +128,10 @@ int main(int argc, char* argv[]) {
ret = rename(tmp_path, output_path); ret = rename(tmp_path, output_path);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "Failed to rename temporary file (%s)\n", strerror(errno)); fprintf(stderr, "Failed to rename temporary file (%s)\n", strerror(errno));
exit(-1); exit(EXIT_FAILURE);
} }
free(tmp_path); free(tmp_path);
exit(0); exit(EXIT_SUCCESS);
} }

View file

@ -61,14 +61,14 @@ int main(int argc, char* argv[]) {
break; break;
default: default:
usage(); usage();
exit(-1); exit(EXIT_FAILURE);
} }
} }
extra = argc - optind; extra = argc - optind;
if (extra < 2 || extra > 3) { if (extra < 2 || extra > 3) {
usage(); usage();
exit(-1); exit(EXIT_FAILURE);
} }
if (extra == 3) { if (extra == 3) {
@ -77,7 +77,7 @@ int main(int argc, char* argv[]) {
if (block_size < 1024 || block_size % 4 != 0) { if (block_size < 1024 || block_size % 4 != 0) {
usage(); usage();
exit(-1); exit(EXIT_FAILURE);
} }
arg_in = argv[optind]; arg_in = argv[optind];
@ -87,7 +87,7 @@ int main(int argc, char* argv[]) {
in = open(arg_in, O_RDONLY | O_BINARY); in = open(arg_in, O_RDONLY | O_BINARY);
if (in < 0) { if (in < 0) {
fprintf(stderr, "Cannot open input file %s\n", arg_in); 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); out = open(arg_out, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0664);
if (out < 0) { if (out < 0) {
fprintf(stderr, "Cannot open output file %s\n", arg_out); 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); s = sparse_file_new(block_size, len);
if (!s) { if (!s) {
fprintf(stderr, "Failed to create sparse file\n"); fprintf(stderr, "Failed to create sparse file\n");
exit(-1); exit(EXIT_FAILURE);
} }
sparse_file_verbose(s); sparse_file_verbose(s);
ret = sparse_file_read(s, in, mode, false); ret = sparse_file_read(s, in, mode, false);
if (ret) { if (ret) {
fprintf(stderr, "Failed to read file\n"); fprintf(stderr, "Failed to read file\n");
exit(-1); exit(EXIT_FAILURE);
} }
ret = sparse_file_write(s, out, false, true, false); ret = sparse_file_write(s, out, false, true, false);
if (ret) { if (ret) {
fprintf(stderr, "Failed to write sparse file\n"); fprintf(stderr, "Failed to write sparse file\n");
exit(-1); exit(EXIT_FAILURE);
} }
close(in); close(in);
close(out); close(out);
exit(0); exit(EXIT_SUCCESS);
} }

View file

@ -41,13 +41,13 @@ int main(int argc, char* argv[]) {
if (argc < 3) { if (argc < 3) {
usage(); usage();
exit(-1); exit(EXIT_FAILURE);
} }
out = open(argv[argc - 1], O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0664); out = open(argv[argc - 1], O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0664);
if (out < 0) { if (out < 0) {
fprintf(stderr, "Cannot open output file %s\n", argv[argc - 1]); fprintf(stderr, "Cannot open output file %s\n", argv[argc - 1]);
exit(-1); exit(EXIT_FAILURE);
} }
for (i = 1; i < argc - 1; i++) { 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); in = open(argv[i], O_RDONLY | O_BINARY);
if (in < 0) { if (in < 0) {
fprintf(stderr, "Cannot open input file %s\n", argv[i]); fprintf(stderr, "Cannot open input file %s\n", argv[i]);
exit(-1); exit(EXIT_FAILURE);
} }
} }
s = sparse_file_import(in, true, false); s = sparse_file_import(in, true, false);
if (!s) { if (!s) {
fprintf(stderr, "Failed to read sparse file\n"); fprintf(stderr, "Failed to read sparse file\n");
exit(-1); exit(EXIT_FAILURE);
} }
if (lseek(out, 0, SEEK_SET) == -1) { 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) { if (sparse_file_write(s, out, false, false, false) < 0) {
fprintf(stderr, "Cannot write output file\n"); fprintf(stderr, "Cannot write output file\n");
exit(-1); exit(EXIT_FAILURE);
} }
sparse_file_destroy(s); sparse_file_destroy(s);
close(in); close(in);
@ -82,5 +82,5 @@ int main(int argc, char* argv[]) {
close(out); close(out);
exit(0); exit(EXIT_SUCCESS);
} }

View file

@ -49,7 +49,7 @@ int main(int argc, char* argv[]) {
if (argc != 4) { if (argc != 4) {
usage(); usage();
exit(-1); exit(EXIT_FAILURE);
} }
max_size = atoll(argv[3]); max_size = atoll(argv[3]);
@ -57,55 +57,55 @@ int main(int argc, char* argv[]) {
in = open(argv[1], O_RDONLY | O_BINARY); in = open(argv[1], O_RDONLY | O_BINARY);
if (in < 0) { if (in < 0) {
fprintf(stderr, "Cannot open input file %s\n", argv[1]); fprintf(stderr, "Cannot open input file %s\n", argv[1]);
exit(-1); exit(EXIT_FAILURE);
} }
s = sparse_file_import(in, true, false); s = sparse_file_import(in, true, false);
if (!s) { if (!s) {
fprintf(stderr, "Failed to import sparse file\n"); fprintf(stderr, "Failed to import sparse file\n");
exit(-1); exit(EXIT_FAILURE);
} }
files = sparse_file_resparse(s, max_size, nullptr, 0); files = sparse_file_resparse(s, max_size, nullptr, 0);
if (files < 0) { if (files < 0) {
fprintf(stderr, "Failed to resparse\n"); fprintf(stderr, "Failed to resparse\n");
exit(-1); exit(EXIT_FAILURE);
} }
out_s = (struct sparse_file**)calloc(sizeof(struct sparse_file*), files); out_s = (struct sparse_file**)calloc(sizeof(struct sparse_file*), files);
if (!out_s) { if (!out_s) {
fprintf(stderr, "Failed to allocate sparse file array\n"); fprintf(stderr, "Failed to allocate sparse file array\n");
exit(-1); exit(EXIT_FAILURE);
} }
files = sparse_file_resparse(s, max_size, out_s, files); files = sparse_file_resparse(s, max_size, out_s, files);
if (files < 0) { if (files < 0) {
fprintf(stderr, "Failed to resparse\n"); fprintf(stderr, "Failed to resparse\n");
exit(-1); exit(EXIT_FAILURE);
} }
for (i = 0; i < files; i++) { for (i = 0; i < files; i++) {
ret = snprintf(filename, sizeof(filename), "%s.%d", argv[2], i); ret = snprintf(filename, sizeof(filename), "%s.%d", argv[2], i);
if (ret >= (int)sizeof(filename)) { if (ret >= (int)sizeof(filename)) {
fprintf(stderr, "Filename too long\n"); fprintf(stderr, "Filename too long\n");
exit(-1); exit(EXIT_FAILURE);
} }
out = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0664); out = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0664);
if (out < 0) { if (out < 0) {
fprintf(stderr, "Cannot open output file %s\n", argv[2]); 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); ret = sparse_file_write(out_s[i], out, false, true, false);
if (ret) { if (ret) {
fprintf(stderr, "Failed to write sparse file\n"); fprintf(stderr, "Failed to write sparse file\n");
exit(-1); exit(EXIT_FAILURE);
} }
close(out); close(out);
} }
close(in); close(in);
exit(0); exit(EXIT_SUCCESS);
} }