Hash :
3498a703
Author :
Date :
2024-07-31T17:10:56
errno: make EEXIST != ENOTEMPTY on AIX Also, improve errno tests. * m4/calloc.m4 (gl_FUNC_CALLOC_GNU): * m4/malloc.m4 (gl_FUNC_MALLOC_GNU): * m4/realloc.m4 (gl_FUNC_REALLOC_GNU): * m4/scandir.m4 (gl_FUNC_SCANDIR): Define _LINUX_SOURCE_COMPAT, as this can sometimes help on AIX. * m4/errno_h.m4 (gl_HEADER_ERRNO_H): Define _LINUX_SOURCE_COMPAT, to make EEXIST != ENOTEMPTY. * m4/strerror_r.m4 (gl_FUNC_STRERROR_R): Define _LINUX_SOURCE_COMPAT, in case someone else does. * modules/errno-tests (Depends-on): Add assert-h, c99. * tests/test-errno.c (e1, ..., e131): Remove, replacing with ... (CHECK_POSIX_ERRNOS, POSITIVE_INTEGER_CONSTANT_EXPRESSION) (INDEXED_BY_ERRNO, ERRNO_COUNT): These new macros. Check that all errno values are positive integer constant expressions. Check that they are all distinct, except perhaps for EWOULDBLOCK == EAGAIN and ENOTSUP == EOPNOTSUPP. Also check ESOCKTNOSUPPORT, added in POSIX.1-2024. Also, check that errno values are distinct except when POSIX says they needn’t be distinct, since POSIX.1-2024 gives license to GNU/Linux’s non-distinct values.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
@node realloc
@subsection @code{realloc}
@findex realloc
POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/realloc.html}
Gnulib module: realloc-posix
Portability problems fixed by Gnulib:
@itemize
@item
Upon failure, the function does not set @code{errno} to @code{ENOMEM} on
some platforms:
mingw, MSVC 14.
@item
On some platforms, @code{realloc (p, 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{realloc-posix} does not allow going over the limit.
@end itemize
Without the @samp{realloc-gnu} module described below, it is not portable
to call @code{realloc} with a size of 0. With a
NULL pointer argument, this is the same ambiguity as @code{malloc (0)}
on whether a unique zero-size object is created. With a non-NULL
pointer argument @code{p}, C17 says that it is implementation-defined
whether @code{realloc (p, 0)} frees @code{p}.
Behavior varies on whether @code{realloc (p, 0)} always frees @code{p}
and successfully returns a null pointer, or always
fails and leaves @code{p} valid, or usually succeeds and returns a
unique zero-size object; a program not suspecting these variations in
semantics will leak memory (either the still-valid @code{p}, or the
non-NULL return value).
Extension: Gnulib provides a module @samp{realloc-gnu} that substitutes a
@code{realloc} implementation that behaves more like the glibc implementation.
It fixes these portability problems:
@itemize
@item
@code{realloc (NULL, 0)} returns @code{NULL} on success on some platforms:
AIX 7.3.
@item
On some platforms, @code{realloc (p, 0)} with non-null @code{p}
might not free @code{p}, or might clobber @code{errno},
or might not return @code{NULL}.
@end itemize