57726f
diff --git a/lib/isc/include/isc/stdio.h b/lib/isc/include/isc/stdio.h
57726f
index 1f44b5a..a3625f9 100644
57726f
--- a/lib/isc/include/isc/stdio.h
57726f
+++ b/lib/isc/include/isc/stdio.h
57726f
@@ -69,6 +69,9 @@ isc_stdio_sync(FILE *f);
57726f
  * direct counterpart in the stdio library.
57726f
  */
57726f
 
57726f
+isc_result_t
57726f
+isc_stdio_fgetc(FILE *f, int *ret);
57726f
+
57726f
 ISC_LANG_ENDDECLS
57726f
 
57726f
 #endif /* ISC_STDIO_H */
57726f
diff --git a/lib/isc/lex.c b/lib/isc/lex.c
57726f
index a8955bc..fc6103b 100644
57726f
--- a/lib/isc/lex.c
57726f
+++ b/lib/isc/lex.c
57726f
@@ -434,17 +434,14 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) {
57726f
 			if (source->is_file) {
57726f
 				stream = source->input;
57726f
 
57726f
-#if defined(HAVE_FLOCKFILE) && defined(HAVE_GETCUNLOCKED)
57726f
-				c = getc_unlocked(stream);
57726f
-#else
57726f
-				c = getc(stream);
57726f
-#endif
57726f
-				if (c == EOF) {
57726f
-					if (ferror(stream)) {
57726f
-						source->result = ISC_R_IOERROR;
57726f
-						result = source->result;
57726f
+				result = isc_stdio_fgetc(stream, &c);
57726f
+
57726f
+				if (result != ISC_R_SUCCESS) {
57726f
+					if (result != ISC_R_EOF) {
57726f
+						source->result = result;
57726f
 						goto done;
57726f
 					}
57726f
+
57726f
 					source->at_eof = true;
57726f
 				}
57726f
 			} else {
57726f
diff --git a/lib/isc/unix/errno2result.c b/lib/isc/unix/errno2result.c
57726f
index 2f12bcc..5bfd648 100644
57726f
--- a/lib/isc/unix/errno2result.c
57726f
+++ b/lib/isc/unix/errno2result.c
57726f
@@ -40,6 +40,7 @@ isc___errno2result(int posixerrno, bool dolog,
57726f
 	case EINVAL:		/* XXX sometimes this is not for files */
57726f
 	case ENAMETOOLONG:
57726f
 	case EBADF:
57726f
+	case EISDIR:
57726f
 		return (ISC_R_INVALIDFILE);
57726f
 	case ENOENT:
57726f
 		return (ISC_R_FILENOTFOUND);
57726f
diff --git a/lib/isc/unix/stdio.c b/lib/isc/unix/stdio.c
57726f
index e60fa65..77f0b13 100644
57726f
--- a/lib/isc/unix/stdio.c
57726f
+++ b/lib/isc/unix/stdio.c
57726f
@@ -149,3 +149,22 @@ isc_stdio_sync(FILE *f) {
57726f
 		return (isc__errno2result(errno));
57726f
 }
57726f
 
57726f
+isc_result_t
57726f
+isc_stdio_fgetc(FILE *f, int *ret) {
57726f
+	int r;
57726f
+	isc_result_t result = ISC_R_SUCCESS;
57726f
+
57726f
+#if defined(HAVE_FLOCKFILE) && defined(HAVE_GETCUNLOCKED)
57726f
+	r = fgetc_unlocked(f);
57726f
+#else
57726f
+	r = fgets(f);
57726f
+#endif
57726f
+
57726f
+	if (r == EOF)
57726f
+		result = ferror(f) ? isc__errno2result(errno) : ISC_R_EOF;
57726f
+
57726f
+	*ret = r;
57726f
+
57726f
+	return result;
57726f
+}
57726f
+