Check for the most basic filename overlaps

Check for the most basic filename overlaps, in case we have the
opportunity to save the user from himself.
This commit is contained in:
H. Peter Anvin 2007-10-01 11:26:31 -07:00
parent fcce07f171
commit 59ddd26aac

29
nasm.c
View File

@ -780,16 +780,25 @@ static void parse_cmdline(int argc, char **argv)
if (!*inname)
report_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
"no input file specified");
else {
if (*errname) {
error_file = fopen(errname, "w");
if (!error_file) {
error_file = stderr; /* Revert to default! */
report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
"cannot open file `%s' for error messages",
errname);
}
}
/* Look for basic command line typos. This definitely doesn't
catch all errors, but it might help cases of fumbled fingers. */
if ((errname && !strcmp(inname, errname)) ||
(outname && !strcmp(inname, outname)) ||
(listname && !strcmp(inname, listname))) {
report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
"file `%s' is both input and output file",
inname);
}
if (*errname) {
error_file = fopen(errname, "w");
if (!error_file) {
error_file = stderr; /* Revert to default! */
report_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
"cannot open file `%s' for error messages",
errname);
}
}
}