diff --git a/ChangeLog b/ChangeLog
index b476f610372e0d45a092d5ff9e14016699659f84..1d176e5c9d64be839f8007b4c84ef48a8572a00b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -333,6 +333,9 @@ CVS code -
 	- Unconditionally blank the statusbar as soon as we're finished
 	  getting input. (DLR, suggested by Benno Schulenberg)
 - utils.c:
+  ngetdelim()
+	- Set errno to EINVAL if stream is not a valid file stream.
+	  This matches the manual page. (DLR)
   nperror()
 	- Simplify. (DLR)
 - winio.c:
diff --git a/src/utils.c b/src/utils.c
index 70601b3d8f95f128dac1aba6d9169d44d2945688..10a4baba8c4923dcffe31c4e826731b1ff65ec56 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -197,7 +197,8 @@ ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream)
     int c;
 
     /* Sanity checks. */
-    if (lineptr == NULL || n == NULL || stream == NULL) {
+    if (lineptr == NULL || n == NULL || stream == NULL ||
+	fileno(stream) == -1) {
 	errno = EINVAL;
 	return -1;
     }