From 3348d52c49f5ea2f320ba3ed69d74bb797b66735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Sun, 17 Sep 2017 05:46:03 +0200 Subject: [PATCH] Don't allow writing to the same file. --- src/files.c | 1 + src/main.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/files.c b/src/files.c index 74f5119..bc65acb 100644 --- a/src/files.c +++ b/src/files.c @@ -26,6 +26,7 @@ int inputPrimes(char *file, List *list) { assert(file); assert(list); + printf("Loading primes from `%s'...\n", file); FILE *in = fopen(file, "r"); if(!in) return 1; mpz_t n; diff --git a/src/main.c b/src/main.c index b2c3ce5..ca59d3f 100644 --- a/src/main.c +++ b/src/main.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -114,6 +115,10 @@ int main(int argc, char *argv[]) { printUsage(argv[0]); return 0; } else if(efile && dfile) { + if(strcmp(efile, dfile) == 0) { + fprintf(stderr, "Error: file paths are the same.\n"); + return 0; + } int err = exportPrimes(efile, dfile, base); if(err) { if(err == 1) fprintf(stderr, "Error: failed to open files.\n");