bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stdio version 2.2.5


From: Graham Nash
Subject: stdio version 2.2.5
Date: Tue, 05 Nov 2002 17:42:44 -0800
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2b) Gecko/20021016

fclose(stdin) does not close file descriptor 0 if stdin has not been referenced. A workaround is to reference the file in some way, for example, fileno(stdin). The problem comes from the io functions not having been set up and then a very nasty overloading of (void*) 0 i.e. NULL, and (int) 0 i.e. fd 0.

Problem occurs on all platforms.

There is no obvious fix other than checking in fclose if the file in question is indeed stdin.

Sorry I could not send you a report in standard form, but I am unable to configure glibc (unsupported configuration) so I have been using just the pieces I needed, thus stdio.

Graham Nash

Here's the code with annotations

   /* Close a stream.  */
   int
   fclose (stream)
        FILE *stream;
   {
     int status;

     if (!__validfp (stream))
       {
         __set_errno (EINVAL);
         return EOF;
       }

     if (stream->__mode.__write &&
         /* Flush the buffer.  */
         __flshfp (stream, EOF) == EOF)
       return EOF;

     /* Free the buffer's storage.  */
     if (stream->__buffer != NULL && !stream->__userbuf)
       free (stream->__buffer);

     /* Close the system file descriptor.  */
     if (stream->__io_funcs.__close != NULL)            /*
   ************* no funcs set up since not referenced */
       status = (*stream->__io_funcs.__close) (stream->__cookie);
     else if (!stream->__seen && stream->__cookie != NULL)        /*
   ******* fd 0 is effectively ignored here */
       status = __stdio_close (stream->__cookie);
     else
       status = 0;

     /* Nuke the stream, making it available for re-use.  */
     __invalidate (stream);

     return status < 0 ? EOF : 0;
   }






reply via email to

[Prev in Thread] Current Thread [Next in Thread]