Don't allow writing to the same file.
This commit is contained in:
parent
c73bfd1501
commit
3348d52c49
@ -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;
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user