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