[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getline() behaviour change
From: |
Bruno Haible |
Subject: |
Re: getline() behaviour change |
Date: |
Thu, 23 Aug 2007 00:57:28 +0200 |
User-agent: |
KMail/1.5.4 |
Jim Meyering wrote:
> Are you advocating support for non-POSIX malloc/realloc?
Sure. gnulib supports - to a large extent - mingw. It uses a malloc
implementation from msvcrt.dll. This malloc does not set errno.
> A *lot* of code expects malloc and realloc to set errno when they fail.
Such code is not portable to plain ISO C 99 systems.
A lot of code also expects malloc and realloc (and other library calls)
to leave errno untouched when they succeed [1]. This is also wrong, even
on POSIX systems.
> Here are the two blocks of code you mention:
>
> *lineptr = (char *) realloc (*lineptr, 120);
> if (*lineptr == NULL)
> {
> result = -1;
> goto unlock_return;
> }
> ...
> new_lineptr = (char *) realloc (*lineptr, needed);
> if (new_lineptr == NULL)
> {
> result = -1;
> goto unlock_return;
> }
>
> in each case, realloc fails, so errno is defined.
Errno is not defined in this case, on mingw.
> unlock_return:
> funlockfile (fp);
> return result;
> }
>
> Upon failure, on a system with the funlockfile function,
> the errno value from a failed realloc may be clobbered
> by that funlockfile call.
Yes. Well spotted!
Bruno
[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7312
- Re: getline.h, (continued)
- Re: getline.h, Simon Josefsson, 2007/08/22
- Re: getline.h, Jim Meyering, 2007/08/22
- Re: getline.h, Bruno Haible, 2007/08/22
- Re: getline.h, Eric Blake, 2007/08/22
- Re: getline.h, Eric Blake, 2007/08/22
- Re: getline.h, Jim Meyering, 2007/08/23
- Re: getline.h, Simon Josefsson, 2007/08/23
- Re: getline.h, Jim Meyering, 2007/08/23
- Re: getline() behaviour change, Bruno Haible, 2007/08/22
- Re: getline() behaviour change, Jim Meyering, 2007/08/22
- Re: getline() behaviour change,
Bruno Haible <=
- Re: getline() behaviour change, Ben Pfaff, 2007/08/22
- Re: getline() behaviour change, Eric Blake, 2007/08/22
- Re: getline() behaviour change, Jim Meyering, 2007/08/24
- Re: getline() behaviour change, Jim Meyering, 2007/08/23
- do not set errno after failing malloc [Re: getline() behaviour change, Jim Meyering, 2007/08/23
- Re: getline() behaviour change, Eric Blake, 2007/08/22