> Date: Mon, 12 Mar 2012 18:02:59 +0000
> From: Federico Schwindt <[email protected]>
> 
> On Mon, Mar 12, 2012 at 1:18 PM, Mark Kettenis <[email protected]> 
> wrote:
> >> Date: Mon, 12 Mar 2012 13:45:58 +0100
> >> From: Jan Klemkow <[email protected]>
> >>
> >> The return of EINVAL on fp NULL comes from me.  I think its even an
> >> invalid argument like the other pointers.
> >
> > We tend to take the position that it is better to crash hard that
> > return an error if an invalid argument gets passed to a library
> > function.  Returning an error just hides bugs because people forget to
> > check return values.  POSIX demands that we return EINVAL if lineptr
> > or n is NULL, so we have to do that even though we consider it to be
> > unhelpful.  But since it doesn't say anything about fp I think you
> > should drop the fp == NULL check.
> 
> That's not correct. POSIX says:
> 
> For the conditions under which the getdelim() and getline() functions
> shall fail and may fail, refer to fgetc

Yes it does, but...

> so if fp is NULL we should return EBADF.

...that's not what the fgetc page says.  It says:

[EBADF]
    The file descriptor underlying stream is not a valid file
    descriptor open for reading.

In fact since fgetc(NULL) segfaults, this statement provides an
additional argument in favour of making these functions crash if fp is
NULL.

Reply via email to