Code

16188d9bc09af07a41d7e8d2961aa4cc4e39c3dc
[nagiosplug.git] / gl / m4 / errno_h.m4
1 # errno_h.m4 serial 5
2 dnl Copyright (C) 2004, 2006, 2008, 2009 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.
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 ECANCELED
38 booboo
39 #endif
40       ],
41       [gl_cv_header_errno_h_complete=no],
42       [gl_cv_header_errno_h_complete=yes])
43   ])
44   if test $gl_cv_header_errno_h_complete = yes; then
45     ERRNO_H=''
46   else
47     gl_CHECK_NEXT_HEADERS([errno.h])
48     ERRNO_H='errno.h'
49   fi
50   AC_SUBST([ERRNO_H])
51   gl_REPLACE_ERRNO_VALUE([EMULTIHOP])
52   gl_REPLACE_ERRNO_VALUE([ENOLINK])
53   gl_REPLACE_ERRNO_VALUE([EOVERFLOW])
54 ])
56 # Assuming $1 = EOVERFLOW.
57 # The EOVERFLOW errno value ought to be defined in <errno.h>, according to
58 # POSIX.  But some systems (like OpenBSD 4.0 or AIX 3) don't define it, and
59 # some systems (like OSF/1) define it when _XOPEN_SOURCE_EXTENDED is defined.
60 # Check for the value of EOVERFLOW.
61 # Set the variables EOVERFLOW_HIDDEN and EOVERFLOW_VALUE.
62 AC_DEFUN([gl_REPLACE_ERRNO_VALUE],
63 [
64   if test -n "$ERRNO_H"; then
65     AC_CACHE_CHECK([for ]$1[ value], [gl_cv_header_errno_h_]$1, [
66       AC_EGREP_CPP([yes],[
67 #include <errno.h>
68 #ifdef ]$1[
69 yes
70 #endif
71       ],
72       [gl_cv_header_errno_h_]$1[=yes],
73       [gl_cv_header_errno_h_]$1[=no])
74       if test $gl_cv_header_errno_h_]$1[ = no; then
75         AC_EGREP_CPP([yes],[
76 #define _XOPEN_SOURCE_EXTENDED 1
77 #include <errno.h>
78 #ifdef ]$1[
79 yes
80 #endif
81           ], [gl_cv_header_errno_h_]$1[=hidden])
82         if test $gl_cv_header_errno_h_]$1[ = hidden; then
83           dnl The macro exists but is hidden.
84           dnl Define it to the same value.
85           AC_COMPUTE_INT([gl_cv_header_errno_h_]$1, $1, [
86 #define _XOPEN_SOURCE_EXTENDED 1
87 #include <errno.h>
88 /* The following two lines are a workaround against an autoconf-2.52 bug.  */
89 #include <stdio.h>
90 #include <stdlib.h>
91 ])
92         fi
93       fi
94     ])
95     case $gl_cv_header_errno_h_]$1[ in
96       yes | no)
97         ]$1[_HIDDEN=0; ]$1[_VALUE=
98         ;;
99       *)
100         ]$1[_HIDDEN=1; ]$1[_VALUE="$gl_cv_header_errno_h_]$1["
101         ;;
102     esac
103     AC_SUBST($1[_HIDDEN])
104     AC_SUBST($1[_VALUE])
105   fi
106 ])
108 dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
109 dnl Remove this when we can assume autoconf >= 2.61.
110 m4_ifdef([AC_COMPUTE_INT], [], [
111   AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])])
112 ])