Subject: Re: Is fclose(NULL) defined?
To: None <matthieu@laas.fr, current-users@NetBSD.ORG>
From: Bert Driehuis <driehuis@playbeing.org>
List: current-users
Date: 09/14/1995 08:29:03
>What's wrong with setting errno to EBADF and return EOF ?

Thou shalt not use NULL file pointers. To detect this condition, you need
very visible diagnostics (I've always felt that 'Segmentation violation,
core dumped" was pretty neat).

Few (if any) people check fclose() return status.

If you protect against NULL file pointers, then why not check for other
illegal file pointers as well? Like fclose(1)? Or fclose("stdout")? I've
seen both in distributed code (and it even worked on their target
platform!)

I've been bitten too often by unneeded defensive programming. I don't see
what we gain by checking for NULL in fclose. NULL is not a valid file
pointer. Program using it deserve to crash. Have to crash, to detect the
error.

We've had a discussion a year ago about the signal set macros, which while
POSIX compliant could do grief in ways that were hard to debug or explain.
Those macros went.

                                        -- Bert Driehuis

------
Bert Driehuis                 God, grant me the serenity to accept the things
driehuis@playbeing.org        I can't change, courage to change the things I
                              can, and the wisdom to know the difference.