| @node malloc | |
| @subsection @code{malloc} | |
| @findex malloc | |
| POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/malloc.html} | |
| Gnulib module: malloc-posix | |
| @mindex malloc-posix | |
| Portability problems fixed by Gnulib: | |
| @itemize | |
| @item | |
| On some platforms, when the function fails it does not set @code{errno}: | |
| mingw, MSVC 14. | |
| @item | |
| On some platforms, when the function fails it might set @code{errno} | |
| to @code{EAGAIN} instead of to @code{ENOMEM}. Although POSIX allows | |
| @code{EAGAIN}, the @code{malloc-posix} module insists on @code{ENOMEM} | |
| which also conforms to POSIX and is GNU-compatible: | |
| Solaris 11.4. | |
| @item | |
| On some platforms, @code{malloc (n)} can succeed even if @code{n} | |
| exceeds @code{PTRDIFF_MAX}. Although this behavior is arguably | |
| allowed by POSIX it can lead to behavior not defined by POSIX later, | |
| so @code{malloc-posix} does not allow going over the limit. | |
| @end itemize | |
| @mindex malloc-gnu | |
| Extension: Gnulib provides a module @samp{malloc-gnu} that substitutes a | |
| @code{malloc} implementation that behaves more like the glibc implementation, | |
| by fixing this portability problem: | |
| @itemize | |
| @item | |
| @code{malloc (0)} returns @code{NULL} on success on some platforms: | |
| AIX 7.3. | |
| @end itemize |