calloc
¶POSIX specification:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/calloc.html
Portability problems fixed by Gnulib:
errno
:
mingw, MSVC 14.
errno
to EAGAIN
instead of to ENOMEM
. Although POSIX allows
EAGAIN
, the calloc-posix
module insists on ENOMEM
which also conforms to POSIX and is GNU-compatible:
Solaris 11.4.
calloc (n, s)
can succeed even if
multiplying n
by s
would exceed PTRDIFF_MAX
or
SIZE_MAX
. Although failing to check for exceeding
PTRDIFF_MAX
is arguably allowed by POSIX it can lead to
undefined behavior later, so calloc-posix
does not allow
going over the limit.
Extension: Gnulib provides a module ‘calloc-gnu’ that substitutes a
calloc
implementation that behaves more like the glibc implementation.
It fixes this portability problem:
calloc (0, s)
and calloc (n, 0)
return NULL
on success
on some platforms:
AIX 7.3.