1baafe
diff --git a/lib/isc/lex.c b/lib/isc/lex.c
1baafe
index cd44fe3..5b7c539 100644
1baafe
--- a/lib/isc/lex.c
1baafe
+++ b/lib/isc/lex.c
1baafe
@@ -27,6 +27,8 @@
1baafe
 #include <isc/string.h>
1baafe
 #include <isc/util.h>
1baafe
 
1baafe
+#include "../errno2result.h"
1baafe
+
1baafe
 typedef struct inputsource {
1baafe
 	isc_result_t result;
1baafe
 	bool is_file;
1baafe
@@ -422,7 +424,7 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) {
1baafe
 #endif /* if defined(HAVE_FLOCKFILE) && defined(HAVE_GETC_UNLOCKED) */
1baafe
 				if (c == EOF) {
1baafe
 					if (ferror(stream)) {
1baafe
-						source->result = ISC_R_IOERROR;
1baafe
+						source->result = isc__errno2result(errno);
1baafe
 						result = source->result;
1baafe
 						goto done;
1baafe
 					}
1baafe
diff --git a/lib/isc/unix/errno2result.c b/lib/isc/unix/errno2result.c
1baafe
index e3e2644..5e58600 100644
1baafe
--- a/lib/isc/unix/errno2result.c
1baafe
+++ b/lib/isc/unix/errno2result.c
1baafe
@@ -37,6 +37,7 @@ isc___errno2result(int posixerrno, bool dolog, const char *file,
1baafe
 	case EINVAL: /* XXX sometimes this is not for files */
1baafe
 	case ENAMETOOLONG:
1baafe
 	case EBADF:
1baafe
+	case EISDIR:
1baafe
 		return (ISC_R_INVALIDFILE);
1baafe
 	case ENOENT:
1baafe
 		return (ISC_R_FILENOTFOUND);