summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeppia <nonso@insicuri.net>2016-06-13 02:16:26 +0200
committerSeppia <nonso@insicuri.net>2016-06-13 02:16:26 +0200
commitebb6099b04e402059ed8728527e9113941ff6cbc (patch)
tree3a560122c6ffad2d1d26a7a156e9137b2a8fa937
parent5df120d45f0386233959b5745037b49daae3b66d (diff)
downloadonetimebluh-ebb6099b04e402059ed8728527e9113941ff6cbc.tar.gz
onetimebluh-ebb6099b04e402059ed8728527e9113941ff6cbc.tar.bz2
onetimebluh-ebb6099b04e402059ed8728527e9113941ff6cbc.zip
anticipated file checking
-rw-r--r--onetimebluh.c14
1 files 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) {