Don't allow writing to the same file.

This commit is contained in:
Nicolás Ortega Froysa 2017-09-17 05:46:03 +02:00
parent c73bfd1501
commit 3348d52c49
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF
2 changed files with 6 additions and 0 deletions

View File

@ -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;

View File

@ -21,6 +21,7 @@
#include <signal.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <gmp.h>
#include <omp.h>
@ -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");