error, strerror-override: Support new errno values from POSIX:2008.
[gnulib.git] / m4 / errno_h.m4
1 # errno_h.m4 serial 11
2 dnl Copyright (C) 2004, 2006, 2008-2012 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN_ONCE([gl_HEADER_ERRNO_H],
8 [
9   AC_REQUIRE([AC_PROG_CC])
10   AC_CACHE_CHECK([for complete errno.h], [gl_cv_header_errno_h_complete], [
11     AC_EGREP_CPP([booboo],[
12 #include <errno.h>
13 #if !defined ENOMSG
14 booboo
15 #endif
16 #if !defined EIDRM
17 booboo
18 #endif
19 #if !defined ENOLINK
20 booboo
21 #endif
22 #if !defined EPROTO
23 booboo
24 #endif
25 #if !defined EMULTIHOP
26 booboo
27 #endif
28 #if !defined EBADMSG
29 booboo
30 #endif
31 #if !defined EOVERFLOW
32 booboo
33 #endif
34 #if !defined ENOTSUP
35 booboo
36 #endif
37 #if !defined ENETRESET
38 booboo
39 #endif
40 #if !defined ECONNABORTED
41 booboo
42 #endif
43 #if !defined ESTALE
44 booboo
45 #endif
46 #if !defined EDQUOT
47 booboo
48 #endif
49 #if !defined ECANCELED
50 booboo
51 #endif
52 #if !defined EOWNERDEAD
53 booboo
54 #endif
55 #if !defined ENOTRECOVERABLE
56 booboo
57 #endif
58       ],
59       [gl_cv_header_errno_h_complete=no],
60       [gl_cv_header_errno_h_complete=yes])
61   ])
62   if test $gl_cv_header_errno_h_complete = yes; then
63     ERRNO_H=''
64   else
65     gl_NEXT_HEADERS([errno.h])
66     ERRNO_H='errno.h'
67   fi
68   AC_SUBST([ERRNO_H])
69   AM_CONDITIONAL([GL_GENERATE_ERRNO_H], [test -n "$ERRNO_H"])
70   gl_REPLACE_ERRNO_VALUE([EMULTIHOP])
71   gl_REPLACE_ERRNO_VALUE([ENOLINK])
72   gl_REPLACE_ERRNO_VALUE([EOVERFLOW])
73 ])
74
75 # Assuming $1 = EOVERFLOW.
76 # The EOVERFLOW errno value ought to be defined in <errno.h>, according to
77 # POSIX.  But some systems (like OpenBSD 4.0 or AIX 3) don't define it, and
78 # some systems (like OSF/1) define it when _XOPEN_SOURCE_EXTENDED is defined.
79 # Check for the value of EOVERFLOW.
80 # Set the variables EOVERFLOW_HIDDEN and EOVERFLOW_VALUE.
81 AC_DEFUN([gl_REPLACE_ERRNO_VALUE],
82 [
83   if test -n "$ERRNO_H"; then
84     AC_CACHE_CHECK([for ]$1[ value], [gl_cv_header_errno_h_]$1, [
85       AC_EGREP_CPP([yes],[
86 #include <errno.h>
87 #ifdef ]$1[
88 yes
89 #endif
90       ],
91       [gl_cv_header_errno_h_]$1[=yes],
92       [gl_cv_header_errno_h_]$1[=no])
93       if test $gl_cv_header_errno_h_]$1[ = no; then
94         AC_EGREP_CPP([yes],[
95 #define _XOPEN_SOURCE_EXTENDED 1
96 #include <errno.h>
97 #ifdef ]$1[
98 yes
99 #endif
100           ], [gl_cv_header_errno_h_]$1[=hidden])
101         if test $gl_cv_header_errno_h_]$1[ = hidden; then
102           dnl The macro exists but is hidden.
103           dnl Define it to the same value.
104           AC_COMPUTE_INT([gl_cv_header_errno_h_]$1, $1, [
105 #define _XOPEN_SOURCE_EXTENDED 1
106 #include <errno.h>
107 /* The following two lines are a workaround against an autoconf-2.52 bug.  */
108 #include <stdio.h>
109 #include <stdlib.h>
110 ])
111         fi
112       fi
113     ])
114     case $gl_cv_header_errno_h_]$1[ in
115       yes | no)
116         ]$1[_HIDDEN=0; ]$1[_VALUE=
117         ;;
118       *)
119         ]$1[_HIDDEN=1; ]$1[_VALUE="$gl_cv_header_errno_h_]$1["
120         ;;
121     esac
122     AC_SUBST($1[_HIDDEN])
123     AC_SUBST($1[_VALUE])
124   fi
125 ])
126
127 dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
128 dnl Remove this when we can assume autoconf >= 2.61.
129 m4_ifdef([AC_COMPUTE_INT], [], [
130   AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])])
131 ])