summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin (Intel) <hpa@zytor.com>2020-06-01 12:32:35 -0700
committerH. Peter Anvin (Intel) <hpa@zytor.com>2020-06-01 12:32:35 -0700
commit5d68f9823e6a4198b8fec73b03c1d0125a2aa6a8 (patch)
tree3afb0e68ef1b345ee363ced135a8916d7a56a49a
parent6e71496e3c8a12838b8e21b97d48746830a07c06 (diff)
downloadnasm-5d68f9823e6a4198b8fec73b03c1d0125a2aa6a8.tar.gz
preproc: error out if an include file exists but can't be opened
If an include file exists, but cannot be opened, that is still a critical error. However, downgrade this from a fatal to a nonfatal error. There really isn't any reason to stop cold here. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
-rw-r--r--asm/preproc.c15
-rw-r--r--include/compiler.h1
-rw-r--r--test/include-self.asm2
3 files changed, 12 insertions, 6 deletions
diff --git a/asm/preproc.c b/asm/preproc.c
index e3014f3e..b9f829ab 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -2241,12 +2241,15 @@ static FILE *inc_fopen(const char *file,
strlist_add(dhead, file);
}
- if (!path) {
- if (omode == INC_NEEDED)
- nasm_fatal("unable to open include file `%s'", file);
- } else {
- if (!fp && omode != INC_PROBE)
- fp = nasm_open_read(path, fmode);
+ if (path && !fp && omode != INC_PROBE)
+ fp = nasm_open_read(path, fmode);
+
+ if (omode == INC_NEEDED && !fp) {
+ if (!path)
+ errno = ENOENT;
+
+ nasm_nonfatal("unable to open include file `%s': %s",
+ file, strerror(errno));
}
if (found_path)
diff --git a/include/compiler.h b/include/compiler.h
index 04cab173..7c937988 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -88,6 +88,7 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+#include <errno.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
diff --git a/test/include-self.asm b/test/include-self.asm
new file mode 100644
index 00000000..234e8ea4
--- /dev/null
+++ b/test/include-self.asm
@@ -0,0 +1,2 @@
+; Test an infinite %include loop
+%include "include-self.asm"