implement -f
diff --git a/NEWS b/NEWS
index 5ae3ae6..8dbc43c 100644
--- a/NEWS
+++ b/NEWS
@@ -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.
diff --git a/src/main.c b/src/main.c
index 32ef4f9..a671c55 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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");
