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: Bruno Haible
Subject: Re: getdelim doesn't set errno on failure?
Date: Wed, 24 Aug 2005 13:58:20 +0200
User-agent: KMail/1.5

Oskar Liljeblad 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.

>   -1, errno!=0                      (malloc failed, assuming malloc set errno)
>   -1, errno!=0                      (realloc failed, assuming realloc set 
> errno)

You cannot assume that malloc() and realloc() set errno upon failure.

  - In ISO C 99, the description of malloc() and realloc() does not mention
    errno. Also, <errno.h> is not required to declare a macro 'ENOMEM'.
  - Windows (mingw) malloc() and realloc() don't always set errno.

But on the other hand, malloc() and realloc() are free to modify errno
even when they succeed. (This happens e.g. on GNU/kFreeBSD, a glibc system.)

Bruno





reply via email to

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