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: Wed, 24 Aug 2005 19:24:10 +0200
User-agent: Mutt/1.5.10i

On Wednesday, August 24, 2005 at 13:20, Bruno Haible wrote:
> > Here's what getdelim in Gnulib returns:
> >   >=0, errno undefined, feof  (getc returned EOF, reached end of file)
> >   >=0, errno!=0, ferror       (getc returned EOF, read failed)
> 
> Actually I think the glibc doc means that -1 is returned if EOF or read
> failure occurs before the first character is read. If it occurs after
> some non-empty string is already read, this non-empty string is returned.

Well, the current Gnulib implementation doesn't behave that way.
It will return 0 if the first call to getc fails (for whatever reason -
error or EOF). AFAIK, the correct way to test getline/getdelim for errors
in the current implementation is:

  errno = 0;
  if (getline(..., fh) <= 0)
    if (ferror(fh) || errno != 0) {
       perror("getline");
    } else if (feof(fh)) {
       /* handle EOF */
    } else {
       errno = ENOMEM;
       perror("getline");
    }
  }

I believe the GNU libc documentation needs to be fixed.

Regards,

Oskar Liljeblad (address@hidden)




reply via email to

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