about summary refs log tree commit diff
path: root/libio/fileno.c
diff options
context:
space:
mode:
Diffstat (limited to 'libio/fileno.c')
-rw-r--r--libio/fileno.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/libio/fileno.c b/libio/fileno.c
index 7ff93e6a81..92334f1564 100644
--- a/libio/fileno.c
+++ b/libio/fileno.c
@@ -32,8 +32,11 @@ fileno (fp)
 {
   CHECK_FILE (fp, EOF);
 
-  if (!(fp->_flags & _IO_IS_FILEBUF))
-    return EOF;
+  if (!(fp->_flags & _IO_IS_FILEBUF) || _IO_fileno (fp) < 0)
+    {
+      __set_errno (EBADF);
+      return -1;
+    }
 
   return _IO_fileno (fp);
 }