From ebb6099b04e402059ed8728527e9113941ff6cbc Mon Sep 17 00:00:00 2001 From: Seppia Date: Mon, 13 Jun 2016 02:16:26 +0200 Subject: anticipated file checking --- onetimebluh.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/onetimebluh.c b/onetimebluh.c index b665fa3..0b4774a 100644 --- a/onetimebluh.c +++ b/onetimebluh.c @@ -50,6 +50,9 @@ int main(int argc, char* argv[]) { break; case 'e': message = argv[optind-1]; + if (access(message, F_OK) == -1) { /* checks the existence of the file and eventually exits */ + error(errno, errno, message); + } command++; comm = 'e'; break; @@ -63,6 +66,9 @@ int main(int argc, char* argv[]) { break; case 'k': keyfile = argv[optind-1]; + if (access(keyfile, F_OK) == -1) { /* look at the comment before */ + error(errno, errno, keyfile); + } break; case 'o': output = argv[optind-1]; @@ -110,14 +116,6 @@ void xor(int ed, char* mess, char* keyf, char* outp) { char* defenoutp = "critt"; char* defdeoutp = "decritt"; - /* Following if-else block check the existence of the files */ - - if (access(mess, F_OK) == -1) { - error(errno, errno, mess); - } else if (access(keyf, F_OK) == -1) { - error(errno, errno, keyf); - } - /* In absence of input by users nex block sets the default values */ if (outp == NULL) { -- cgit v1.2.3