once: Fix pthread-rwlock crashes with clang (regr. 2024-08-07).
[gnulib.git] / m4 / errno_h.m4
blob920ea6cc65374a4926026cf2ddd21a125c948cbd
1 # errno_h.m4
2 # serial 18
3 dnl Copyright (C) 2004, 2006, 2008-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_PREREQ([2.61])
10 AC_DEFUN_ONCE([gl_HEADER_ERRNO_H],
12   AC_REQUIRE([AC_PROG_CC])
14   dnl Through the dependency on module extensions-aix, _LINUX_SOURCE_COMPAT
15   dnl gets defined already before this macro gets invoked.  This persuades
16   dnl AIX 7.3 errno.h to assign ENOTEMPTY a value different than EEXIST.
18   AC_CACHE_CHECK([for complete errno.h], [gl_cv_header_errno_h_complete], [
19     AC_EGREP_CPP([booboo],[
20 #include <errno.h>
21 #if !defined ETXTBSY
22 booboo
23 #endif
24 #if !defined ENOMSG
25 booboo
26 #endif
27 #if !defined EIDRM
28 booboo
29 #endif
30 #if !defined ENOLINK
31 booboo
32 #endif
33 #if !defined EPROTO
34 booboo
35 #endif
36 #if !defined EMULTIHOP
37 booboo
38 #endif
39 #if !defined EBADMSG
40 booboo
41 #endif
42 #if !defined EOVERFLOW
43 booboo
44 #endif
45 #if !defined ENOTSUP
46 booboo
47 #endif
48 #if !defined ENETRESET
49 booboo
50 #endif
51 #if !defined ECONNABORTED
52 booboo
53 #endif
54 #if !defined ESTALE
55 booboo
56 #endif
57 #if !defined EDQUOT
58 booboo
59 #endif
60 #if !defined ECANCELED
61 booboo
62 #endif
63 #if !defined EOWNERDEAD
64 booboo
65 #endif
66 #if !defined ENOTRECOVERABLE
67 booboo
68 #endif
69 #if !defined EILSEQ
70 booboo
71 #endif
72 #if !defined ESOCKTNOSUPPORT
73 booboo
74 #endif
75       ],
76       [gl_cv_header_errno_h_complete=no],
77       [gl_cv_header_errno_h_complete=yes])
78   ])
79   if test $gl_cv_header_errno_h_complete = yes; then
80     GL_GENERATE_ERRNO_H=false
81   else
82     gl_NEXT_HEADERS([errno.h])
83     GL_GENERATE_ERRNO_H=true
84   fi
85   gl_REPLACE_ERRNO_VALUE([EMULTIHOP])
86   gl_REPLACE_ERRNO_VALUE([ENOLINK])
87   gl_REPLACE_ERRNO_VALUE([EOVERFLOW])
90 # Assuming $1 = EOVERFLOW.
91 # The EOVERFLOW errno value ought to be defined in <errno.h>, according to
92 # POSIX.  But some systems (like OpenBSD 4.0 or AIX 3) don't define it, and
93 # some systems (like OSF/1) define it when _XOPEN_SOURCE_EXTENDED is defined.
94 # Check for the value of EOVERFLOW.
95 # Set the variables EOVERFLOW_HIDDEN and EOVERFLOW_VALUE.
96 AC_DEFUN([gl_REPLACE_ERRNO_VALUE],
98   if $GL_GENERATE_ERRNO_H; then
99     AC_CACHE_CHECK([for ]$1[ value], [gl_cv_header_errno_h_]$1, [
100       AC_EGREP_CPP([yes],[
101 #include <errno.h>
102 #ifdef ]$1[
104 #endif
105       ],
106       [gl_cv_header_errno_h_]$1[=yes],
107       [gl_cv_header_errno_h_]$1[=no])
108       if test $gl_cv_header_errno_h_]$1[ = no; then
109         AC_EGREP_CPP([yes],[
110 #define _XOPEN_SOURCE_EXTENDED 1
111 #include <errno.h>
112 #ifdef ]$1[
114 #endif
115           ], [gl_cv_header_errno_h_]$1[=hidden])
116         if test $gl_cv_header_errno_h_]$1[ = hidden; then
117           dnl The macro exists but is hidden.
118           dnl Define it to the same value.
119           AC_COMPUTE_INT([gl_cv_header_errno_h_]$1, $1, [
120 #define _XOPEN_SOURCE_EXTENDED 1
121 #include <errno.h>
122 /* The following two lines are a workaround against an autoconf-2.52 bug.  */
123 #include <stdio.h>
124 #include <stdlib.h>
126         fi
127       fi
128     ])
129     case $gl_cv_header_errno_h_]$1[ in
130       yes | no)
131         ]$1[_HIDDEN=0; ]$1[_VALUE=
132         ;;
133       *)
134         ]$1[_HIDDEN=1; ]$1[_VALUE="$gl_cv_header_errno_h_]$1["
135         ;;
136     esac
137     AC_SUBST($1[_HIDDEN])
138     AC_SUBST($1[_VALUE])
139   fi