2015-06-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / libjava / classpath / m4 / ax_func_which_gethostbyname_r.m4
blob6fbe8eedeaa45691813c4e8d24bd1cab8391d78e
1 # m4/ax_func_which_gethostbyname_r.m4
3 # Copyright © 2005 Caolan McNamara <caolan@skynet.ie>
4 # Copyright © 2005 Daniel Richard G. <skunk@iskunk.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 # 02111-1307, USA.
21 # As a special exception, the respective Autoconf Macro's copyright
22 # owner gives unlimited permission to copy, distribute and modify the
23 # configure scripts that are the output of Autoconf when processing
24 # the Macro. You need not follow the terms of the GNU General Public
25 # License when using or distributing such scripts, even though
26 # portions of the text of the Macro appear in them. The GNU General
27 # Public License (GPL) does govern all other use of the material that
28 # constitutes the Autoconf Macro.
30 # This special exception to the GPL applies to versions of the
31 # Autoconf Macro released by the Autoconf Macro Archive. When you make
32 # and distribute a modified version of the Autoconf Macro, you may
33 # extend this special exception to the GPL to apply to your modified
34 # version as well.
37 AC_DEFUN([AX_FUNC_WHICH_GETHOSTBYNAME_R], [
39     AC_LANG_PUSH(C)
40     AC_MSG_CHECKING([how many arguments gethostbyname_r() takes])
42     AC_CACHE_VAL(ac_cv_func_which_gethostbyname_r, [
44 ################################################################
46 ac_cv_func_which_gethostbyname_r=unknown
49 # ONE ARGUMENT (sanity check)
52 # This should fail, as there is no variant of gethostbyname_r() that takes
53 # a single argument. If it actually compiles, then we can assume that
54 # netdb.h is not declaring the function, and the compiler is thereby
55 # assuming an implicit prototype. In which case, we're out of luck.
57 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
58     AC_LANG_PROGRAM(
59         [[#include <netdb.h>]],
60         [[
61             char *name = "www.gnu.org";
62             (void)gethostbyname_r(name) /* ; */
63         ]])])],
64     ac_cv_func_which_gethostbyname_r=no)
67 # SIX ARGUMENTS
68 # (e.g. Linux)
71 if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
73 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
74     AC_LANG_PROGRAM(
75         [[#include <netdb.h>]],
76         [[
77             char *name = "www.gnu.org";
78             struct hostent ret, *retp;
79             char buf@<:@1024@:>@;
80             int buflen = 1024;
81             int my_h_errno;
82             (void)gethostbyname_r(name, &ret, buf, buflen, &retp, &my_h_errno) /* ; */
83         ]])])],
84     ac_cv_func_which_gethostbyname_r=six)
89 # FIVE ARGUMENTS
90 # (e.g. Solaris)
93 if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
95 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
96     AC_LANG_PROGRAM(
97         [[#include <netdb.h>]],
98         [[
99             char *name = "www.gnu.org";
100             struct hostent ret;
101             char buf@<:@1024@:>@;
102             int buflen = 1024;
103             int my_h_errno;
104             (void)gethostbyname_r(name, &ret, buf, buflen, &my_h_errno) /* ; */
105         ]])])],
106     ac_cv_func_which_gethostbyname_r=five)
111 # THREE ARGUMENTS
112 # (e.g. AIX, HP-UX, Tru64)
115 if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
117 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
118     AC_LANG_PROGRAM(
119         [[#include <netdb.h>]],
120         [[
121             char *name = "www.gnu.org";
122             struct hostent ret;
123             struct hostent_data data;
124             (void)gethostbyname_r(name, &ret, &data) /* ; */
125         ]])])],
126     ac_cv_func_which_gethostbyname_r=three)
130 ################################################################
132 ]) dnl end AC_CACHE_VAL
134 case "$ac_cv_func_which_gethostbyname_r" in
135     three)
136     AC_MSG_RESULT([three])
137     AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_3], 1, [three-argument gethostbyname_r])
138     ;;
140     five)
141     AC_MSG_RESULT([five])
142     AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_5], 1, [five-argument gethostbyname_r])
143     ;;
145     six)
146     AC_MSG_RESULT([six])
147     AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_6], 1, [six-argument gethostbyname_r])
148     ;;
150     no)
151     AC_MSG_RESULT([cannot find function declaration in netdb.h])
152     ;;
154     unknown)
155     AC_MSG_RESULT([can't tell])
156     ;;
158     *)
159     AC_MSG_ERROR([internal error])
160     ;;
161 esac
163 AC_LANG_POP(C)
165 ]) dnl end AC_DEFUN