Subject: Re: Is fclose(NULL) defined?
To: Olaf Seibert <rhialto@mbfys.kun.nl>
From: Luke Mewburn <lukem@telstra.com.au>
List: current-users
Date: 09/12/1995 12:02:27
> Arne Helme wrote:
> > Could someone please tell what the expected result of fclose() on a
> > null-pointer should be.  On NetBSD-current/i386 I get a segmentation
> > fault.  Is it just bad programming practice to not check whether a
> > file pointer is NULL before it is passed to fclose()?  I notice that

> Yes.

> > on DEC/OSF, DEC/Ultrix, and HP-UX it seems to be OK to invoke fclose()
> > with a NULL poiner.

> The implementors of those versions of fclose() might have confused
> it with fflush(). Fflush() *can* be called with a NULL argument
> (meaning to fflush() all output files). Not that it matters, since
> fclose(NULL) is undefined behaviour, which means anything can
> happen, including not crashing.

Yes, but IMHO libc should error-check stuff, even simple null pointer
checks would save a lot of hassles.

-- 
Luke Mewburn <luke.mewburn@itg.telstra.com.au>

    Don't steal. The Government (and the Banks) hate competition.  - (anon)