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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
/* Test of <errno.h> substitute.
Copyright (C) 2008-2024 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* Written by Bruno Haible <bruno@clisp.org>, 2008. */
#include <config.h>
#include <errno.h>
/* Check all POSIX-defined errno values, using M (v) to check value v. */
#define CHECK_POSIX_ERRNOS(m) \
m (E2BIG) \
m (EACCES) \
m (EADDRINUSE) \
m (EADDRNOTAVAIL) \
m (EAFNOSUPPORT) \
m (EAGAIN) \
m (EALREADY) \
m (EBADF) \
m (EBADMSG) \
m (EBUSY) \
m (ECANCELED) \
m (ECHILD) \
m (ECONNABORTED) \
m (ECONNREFUSED) \
m (ECONNRESET) \
m (EDEADLK) \
m (EDESTADDRREQ) \
m (EDOM) \
m (EDQUOT) \
m (EEXIST) \
m (EFAULT) \
m (EFBIG) \
m (EHOSTUNREACH) \
m (EIDRM) \
m (EILSEQ) \
m (EINPROGRESS) \
m (EINTR) \
m (EINVAL) \
m (EIO) \
m (EISCONN) \
m (EISDIR) \
m (ELOOP) \
m (EMFILE) \
m (EMLINK) \
m (EMSGSIZE) \
m (EMULTIHOP) \
m (ENAMETOOLONG) \
m (ENETDOWN) \
m (ENETRESET) \
m (ENETUNREACH) \
m (ENFILE) \
m (ENOBUFS) \
m (ENODEV) \
m (ENOENT) \
m (ENOEXEC) \
m (ENOLCK) \
m (ENOLINK) \
m (ENOMEM) \
m (ENOMSG) \
m (ENOPROTOOPT) \
m (ENOSPC) \
m (ENOSYS) \
m (ENOTCONN) \
m (ENOTDIR) \
m (ENOTEMPTY) \
m (ENOTRECOVERABLE) \
m (ENOTSOCK) \
m (ENOTSUP) \
m (ENOTTY) \
m (ENXIO) \
m (EOPNOTSUPP) \
m (EOVERFLOW) \
m (EOWNERDEAD) \
m (EPERM) \
m (EPIPE) \
m (EPROTO) \
m (EPROTONOSUPPORT) \
m (EPROTOTYPE) \
m (ERANGE) \
m (EROFS) \
m (ESOCKTNOSUPPORT) \
m (ESPIPE) \
m (ESRCH) \
m (ESTALE) \
m (ETIMEDOUT) \
m (ETXTBSY) \
m (EWOULDBLOCK) \
m (EXDEV) \
/* end of CHECK_POSIX_ERRNOS */
/* Verify that the POSIX mandated errno values can be used as integer
constant expressions and are all positive. */
#define POSITIVE_INTEGER_CONSTANT_EXPRESSION(e) static_assert (0 < (e) << 0);
CHECK_POSIX_ERRNOS (POSITIVE_INTEGER_CONSTANT_EXPRESSION)
int
main ()
{
/* Verify that errno can be assigned. */
errno = EOVERFLOW;
/* Check that errno values all differ, except possibly for
EWOULDBLOCK == EAGAIN and ENOTSUP == EOPNOTSUPP. */
#define INDEXED_BY_ERRNO(e) [e] = 1,
#define ERRNO_COUNT(e) 0,
static char const
indexed_by_errno[] = { CHECK_POSIX_ERRNOS (INDEXED_BY_ERRNO) },
errno_count[] = { CHECK_POSIX_ERRNOS (ERRNO_COUNT) };
int distinct_errnos = 0;
for (int i = 0; i < sizeof indexed_by_errno; i++)
distinct_errnos += indexed_by_errno[i];
return ((sizeof errno_count
- (EWOULDBLOCK == EAGAIN)
- (ENOTSUP == EOPNOTSUPP))
!= distinct_errnos);
}