bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getdelim doesn't set errno on failure?


From: Oskar Liljeblad
Subject: Re: getdelim doesn't set errno on failure?
Date: Tue, 23 Aug 2005 21:48:27 +0200
User-agent: Mutt/1.5.10i

On Tuesday, August 23, 2005 at 17:59, Jim Meyering wrote:
> Oskar Liljeblad <address@hidden> wrote:
> > I don't know if this is necessary or necessarily correct, but
> > it seems getdelim doesn't always set errno on failure (when it
> > returns -1).
> >
> > From what I can tell, the test below (needed < cur_len) is to
> > test for overflow.
> 
> Right.
> How about using ENOMEM instead?

Yes, that would be useful. It is hard as it is to handle errors from
getline. Also the documentation from GNU libc seems wrong:

     If an error occurs or end of file is reached without any bytes
     read, `getline' returns `-1'.

Here's what getdelim in Gnulib returns:

  -1, errno=EINVAL            (an argument is NULL)
  -1, errno!=0                (malloc failed, assuming malloc set errno)
  >=0, errno undefined, feof  (getc returned EOF, reached end of file)
  >=0, errno!=0, ferror       (getc returned EOF, read failed)
  -1, errno undefined         (arithmetic overflow)
  -1, errno!=0                (realloc failed, assuming realloc set errno)

So getline/getdelim only returns -1 on invalid arguments or an out of
memory condition, never on I/O errors or EOF!

Or did I miss something?

Regards,

Oskar Liljeblad (address@hidden)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]