about summary refs log tree commit diff
path: root/libio
diff options
context:
space:
mode:
Diffstat (limited to 'libio')
-rw-r--r--libio/fileno.c7
-rw-r--r--libio/fileops.c2
-rw-r--r--libio/iofopncook.c5
-rw-r--r--libio/libioP.h4
-rw-r--r--libio/oldfileops.c2
5 files changed, 14 insertions, 6 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);
 }
diff --git a/libio/fileops.c b/libio/fileops.c
index 8d480ad08b..8ced77b4c3 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -151,7 +151,7 @@ _IO_new_file_close_it (fp)
 
   _IO_un_link (fp);
   fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS;
-  fp->_fileno = EOF;
+  fp->_fileno = -1;
   fp->_offset = _IO_pos_BAD;
 
   return close_status ? close_status : write_status;
diff --git a/libio/iofopncook.c b/libio/iofopncook.c
index 85ea35c22e..7b76826031 100644
--- a/libio/iofopncook.c
+++ b/libio/iofopncook.c
@@ -167,5 +167,10 @@ fopencookie (cookie, mode, io_functions)
     _IO_mask_flags (&new_f->cfile.__file, read_write,
 		    _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
 
+  /* We use a negative number different from -1 for _fileno to mark that
+     this special stream is not associated with a real file, but still has
+     to be treated as such.  */
+  new_f->cfile.__file._fileno = -2;
+
   return &new_f->cfile.__file;
 }
diff --git a/libio/libioP.h b/libio/libioP.h
index 775f44588c..64256a9199 100644
--- a/libio/libioP.h
+++ b/libio/libioP.h
@@ -98,7 +98,7 @@ extern "C" {
 #endif
 
 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
-   It does not delete (free) it, but does everything else to finalize it/
+   It does not delete (free) it, but does everything else to finalize it.
    It matches the streambuf::~streambuf virtual destructor.  */
 typedef void (*_IO_finish_t) __PMT ((_IO_FILE *, int)); /* finalize */
 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
@@ -422,7 +422,7 @@ extern int _IO_file_stat __P ((_IO_FILE *, void *));
 extern int _IO_file_close __P ((_IO_FILE *));
 extern int _IO_file_underflow __P ((_IO_FILE *));
 extern int _IO_file_overflow __P ((_IO_FILE *, int));
-#define _IO_file_is_open(__fp) ((__fp)->_fileno >= 0)
+#define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
 extern void _IO_file_init __P ((_IO_FILE *));
 extern _IO_FILE* _IO_file_attach __P ((_IO_FILE *, int));
 extern _IO_FILE* _IO_file_open __P ((_IO_FILE *, const char *, int, int,
diff --git a/libio/oldfileops.c b/libio/oldfileops.c
index d65c272d48..02445215df 100644
--- a/libio/oldfileops.c
+++ b/libio/oldfileops.c
@@ -149,7 +149,7 @@ _IO_old_file_close_it (fp)
 
   _IO_un_link (fp);
   fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS;
-  fp->_fileno = EOF;
+  fp->_fileno = -1;
   fp->_old_offset = _IO_pos_BAD;
 
   return close_status ? close_status : write_status;