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



Reply via email to