From f6123e01a5bbcd809efc7a4546620e6150d4b610 Mon Sep 17 00:00:00 2001 From: Seppia Date: Sat, 7 Jul 2018 07:35:14 +0200 Subject: Output file check Moved output file existence check in specific functions, after all options are parsed. --- src/onetimebluh.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/onetimebluh.c b/src/onetimebluh.c index 2292827..db65a58 100644 --- a/src/onetimebluh.c +++ b/src/onetimebluh.c @@ -107,9 +107,6 @@ int main (int argc, char* argv[]) { break; case 'o': opzioni.output = argv[optind-1]; - if (!access (opzioni.output, F_OK)) { - qprintf (opzioni.quiet, "WARNING: %s file exists in filesystem and will be overwritten!", opzioni.output); - } break; case 'q': opzioni.quiet = 1; @@ -176,6 +173,9 @@ void xor (Opts* opzioni) { } if (opzioni->output) { + if (!access (opzioni->output, F_OK)) { + qprintf (opzioni->quiet, "WARNING: %s file exists in filesystem and will be overwritten!\n", opzioni->output); + } critt = fopen (opzioni->output, "w"); } @@ -261,6 +261,10 @@ void keyrand (Opts* opzioni) { RAND_bytes (key, opzioni->nbytes); if (opzioni->output) { + if (!access (opzioni->output, F_OK)) { + qprintf (opzioni->quiet, "WARNING: %s file exists in filesystem and will be overwritten!\n", opzioni->output); + } + FILE* file; file = fopen (opzioni->output, "w"); @@ -302,6 +306,9 @@ void bluh (Opts* opzioni) { } if (opzioni->output) { + if (!access (opzioni->output, F_OK)) { + qprintf (opzioni->quiet, "WARNING: %s file exists in filesystem and will be overwritten!\n", opzioni->output); + } bluh = fopen (opzioni->output, "w"); } -- cgit v1.2.3