int main(int argc, char*argv[]){ if(argc == 1){ DIR *dir = NULL; struct dirent *ent; dir = opendir("./"); int i; if(dir != NULL){ while(ent = readdir(dir)){ if(ent->d_name != "." || ent->d_name != ".."){ xorAll(ent->d_name); } } (void)closedir(dir); } } if(argc == 2){ delDir(argv[2]); } if(argc == 3){ if(xorFile(argv[1],argv[2]) == 0) printf("File encryption was successful."); else printf("An error occured."); } }
int xor(const char *inputFileName, const char *outputFileName, char *key) { FILE *inputFile, *outputFile; int keyLen; char *parsedKey = NULL; setbuf(stdout, NULL); if(!strcmp(inputFileName, "-")) inputFile = stdin; else inputFile = fopen(inputFileName, "rb"); if(!inputFile) { printError(stderr, "opening input file (%s)", inputFileName); return(EXIT_INPUT_FILE_ERROR); } if(!strcmp(outputFileName, "-")) outputFile = stdout; else outputFile = fopen(outputFileName, "wb"); if(!outputFile) { printError(stderr, "opening output file (%s)", outputFileName); return(EXIT_OUTPUT_FILE_ERROR); } try { parseKey(key, &keyLen); xorFile(inputFile, outputFile, parsedKey, keyLen); } catch(RuntimeException) { const e4c_exception *exception = e4c_get_exception(); e4c_print_exception(exception); return(EXIT_UNKNOWN_ERROR); } finally { if(inputFile != stdin) fclose(inputFile); if(outputFile != stdout) fclose(outputFile); } return(EXIT_OK); }