1
0
mirror of https://github.com/kspalaiologos/bzip3.git synced 2026-10-23 14:48:53 +03:00

implement -f

This commit is contained in:
Kamila Szewczyk
2022-05-16 11:16:00 +02:00
parent a8a9dd9be0
commit 55c8d5ce7e
2 changed files with 13 additions and 1 deletions

2
NEWS
View File

@@ -11,3 +11,5 @@ v1.1.3:
* fix a serious stdin/stdout CRLF bug on Windows that corrupted the data.
* imply `-c` when a stream isn't opened thus preventing potential UB.
* bzip3 file format documentation.
* increase the maximum amount of parallel workers to 24.
* prevent accidentally overwriting output; add the `-f` command-line flag.

View File

@@ -53,7 +53,7 @@ int main(int argc, char * argv[]) {
// input and output file names
char *input = NULL, *output = NULL;
char *bz3_file = NULL, *regular_file = NULL;
int no_bz3_suffix = 0;
int no_bz3_suffix = 0, force = 0;
// command line arguments
int force_stdstreams = 0, workers = 0;
@@ -73,6 +73,8 @@ int main(int argc, char * argv[]) {
mode = -1;
} else if (argv[i][1] == 't') {
mode = 2;
} else if (argv[i][1] == 'f') {
force = 1;
} else if (argv[i][1] == 'b') {
if (i + 1 >= argc) {
fprintf(stderr, "Error: -b requires an argument.\n");
@@ -142,6 +144,7 @@ int main(int argc, char * argv[]) {
fprintf(stderr, " -d: decode\n");
fprintf(stderr, " -t: test\n");
fprintf(stderr, " -h: help\n");
fprintf(stderr, " -f: force overwrite output if it already exists\n");
fprintf(stderr, " -v: version\n");
fprintf(stderr, "Extra flags:\n");
fprintf(stderr, " -c: force reading/writing from standard streams\n");
@@ -210,6 +213,13 @@ int main(int argc, char * argv[]) {
return 1;
}
if(access(output, F_OK) == 0) {
if (!force) {
fprintf(stderr, "Error: output file already exists. Use -f to force overwrite.\n");
return 1;
}
}
output_des = fopen(output, "wb");
if (output_des == NULL) {
perror("open");