Re: Write to a closed stream bug.

Steffen Ullrich (ccrlphr@xensei.com)
Fri, 19 Dec 1997 13:20:59 +0100


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.