lkml.org 
[lkml]   [1997]   [Dec]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Write to a closed stream bug.
On Fri, Dec 19, 1997 at 12:42:05PM +0100, Pavel Machek wrote:
> > How about this: If you close the FILE* future writes to it are added to the
> > buffer of the (closed) FILE* until it is filled and then the application simple blocks
> > w/o a notice (it cannot flush the buffer because the file is closed).
> > Happened to me several times on DEC UNIX (at least with stderr).
> > This is what I call a really bad behavior.
>
> No. This is 'good' behaviour. printf does what it is expected to do. I
> do not like printf discarding data silently. Everything else
> (incl. writing to wrong file, blocking, etc. is ok with me.)

Remember, the FILE* was already closed!
So it blocked a write to a closed file descriptor. I would expect to get an
error back, or, if this is because of the semantics of printf not possible
(returns number of characters printed according to the manual) I would need to
check find another way to check for an error.

Unfortunatly ferror only checks the error flag, feof the EOF flag of the FILE,
non of these gets set on fclose. the only way I found is to query fileno which
reports an invalid fd of -1.

I wouldn't call it a bug, it's more a design, which could get some improvements.

\
 
 \ /
  Last update: 2005-03-22 13:40    [W:0.070 / U:0.356 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site