Subject: Re: Is fclose(NULL) defined?
To: None <arne@pegasus.esprit.ec.org, current-users@NetBSD.ORG>
From: Olaf Seibert <rhialto@mbfys.kun.nl>
List: current-users
Date: 09/12/1995 01:57:28
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.
-Olaf.
--
___ Copyright 1995 Olaf 'Rhialto' Seibert. All Rights Reserved.
\X/ You are not allowed to read this using any kind of Micro$oft product.