1# ================================================================================== 2# https://www.gnu.org/software/autoconf-archive/ax_func_which_gethostbyname_r.html 3# ================================================================================== 4# 5# SYNOPSIS 6# 7# AX_FUNC_WHICH_GETHOSTBYNAME_R 8# 9# DESCRIPTION 10# 11# Determines which historical variant of the gethostbyname_r() call 12# (taking three, five, or six arguments) is available on the system and 13# defines one of the following macros accordingly: 14# 15# HAVE_FUNC_GETHOSTBYNAME_R_6 16# HAVE_FUNC_GETHOSTBYNAME_R_5 17# HAVE_FUNC_GETHOSTBYNAME_R_3 18# 19# as well as 20# 21# HAVE_GETHOSTBYNAME_R 22# 23# If used in conjunction with gethostname.c, the API demonstrated in 24# test.c can be used regardless of which gethostbyname_r() is available. 25# These example files can be found at 26# http://www.csn.ul.ie/~caolan/publink/gethostbyname_r 27# 28# based on David Arnold's autoconf suggestion in the threads faq 29# 30# Originally named "AC_caolan_FUNC_WHICH_GETHOSTBYNAME_R". Rewritten for 31# Autoconf 2.5x, and updated for 2.68 by Daniel Richard G. 32# 33# LICENSE 34# 35# Copyright (c) 2008 Caolan McNamara <caolan@skynet.ie> 36# Copyright (c) 2008 Daniel Richard G. <skunk@iskunk.org> 37# 38# This program is free software; you can redistribute it and/or modify it 39# under the terms of the GNU General Public License as published by the 40# Free Software Foundation; either version 2 of the License, or (at your 41# option) any later version. 42# 43# This program is distributed in the hope that it will be useful, but 44# WITHOUT ANY WARRANTY; without even the implied warranty of 45# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 46# Public License for more details. 47# 48# You should have received a copy of the GNU General Public License along 49# with this program. If not, see <https://www.gnu.org/licenses/>. 50# 51# As a special exception, the respective Autoconf Macro's copyright owner 52# gives unlimited permission to copy, distribute and modify the configure 53# scripts that are the output of Autoconf when processing the Macro. You 54# need not follow the terms of the GNU General Public License when using 55# or distributing such scripts, even though portions of the text of the 56# Macro appear in them. The GNU General Public License (GPL) does govern 57# all other use of the material that constitutes the Autoconf Macro. 58# 59# This special exception to the GPL applies to versions of the Autoconf 60# Macro released by the Autoconf Archive. When you make and distribute a 61# modified version of the Autoconf Macro, you may extend this special 62# exception to the GPL to apply to your modified version as well. 63 64#serial 8 65 66AC_DEFUN([AX_FUNC_WHICH_GETHOSTBYNAME_R], [ 67 68 AC_LANG_PUSH([C]) 69 AC_MSG_CHECKING([how many arguments gethostbyname_r() takes]) 70 71 AC_CACHE_VAL([ac_cv_func_which_gethostbyname_r], [ 72 73################################################################ 74 75ac_cv_func_which_gethostbyname_r=unknown 76 77# 78# ONE ARGUMENT (sanity check) 79# 80 81# This should fail, as there is no variant of gethostbyname_r() that takes 82# a single argument. If it actually compiles, then we can assume that 83# netdb.h is not declaring the function, and the compiler is thereby 84# assuming an implicit prototype. In which case, we're out of luck. 85# 86AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>], 87 [ 88 char *name = "www.gnu.org"; 89 (void)gethostbyname_r(name) /* ; */ 90 ])], 91 [ac_cv_func_which_gethostbyname_r=no]) 92 93# 94# SIX ARGUMENTS 95# (e.g. Linux) 96# 97 98if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then 99 100AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>], 101 [ 102 char *name = "www.gnu.org"; 103 struct hostent ret, *retp; 104 char buf@<:@1024@:>@; 105 int buflen = 1024; 106 int my_h_errno; 107 (void)gethostbyname_r(name, &ret, buf, buflen, &retp, &my_h_errno) /* ; */ 108 ])], 109 [ac_cv_func_which_gethostbyname_r=six]) 110 111fi 112 113# 114# FIVE ARGUMENTS 115# (e.g. Solaris) 116# 117 118if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then 119 120AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>], 121 [ 122 char *name = "www.gnu.org"; 123 struct hostent ret; 124 char buf@<:@1024@:>@; 125 int buflen = 1024; 126 int my_h_errno; 127 (void)gethostbyname_r(name, &ret, buf, buflen, &my_h_errno) /* ; */ 128 ])], 129 [ac_cv_func_which_gethostbyname_r=five]) 130 131fi 132 133# 134# THREE ARGUMENTS 135# (e.g. AIX, HP-UX, Tru64) 136# 137 138if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then 139 140AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>], 141 [ 142 char *name = "www.gnu.org"; 143 struct hostent ret; 144 struct hostent_data data; 145 (void)gethostbyname_r(name, &ret, &data) /* ; */ 146 ])], 147 [ac_cv_func_which_gethostbyname_r=three]) 148 149fi 150 151################################################################ 152 153]) dnl end AC_CACHE_VAL 154 155case "$ac_cv_func_which_gethostbyname_r" in 156 three|five|six) 157 AC_DEFINE([HAVE_GETHOSTBYNAME_R], [1], 158 [Define to 1 if you have some form of gethostbyname_r().]) 159 ;; 160esac 161 162case "$ac_cv_func_which_gethostbyname_r" in 163 three) 164 AC_MSG_RESULT([three]) 165 AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_3], [1], 166 [Define to 1 if you have the three-argument form of gethostbyname_r().]) 167 ;; 168 169 five) 170 AC_MSG_RESULT([five]) 171 AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_5], [1], 172 [Define to 1 if you have the five-argument form of gethostbyname_r().]) 173 ;; 174 175 six) 176 AC_MSG_RESULT([six]) 177 AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_6], [1], 178 [Define to 1 if you have the six-argument form of gethostbyname_r().]) 179 ;; 180 181 no) 182 AC_MSG_RESULT([cannot find function declaration in netdb.h]) 183 ;; 184 185 unknown) 186 AC_MSG_RESULT([can't tell]) 187 ;; 188 189 *) 190 AC_MSG_ERROR([internal error]) 191 ;; 192esac 193 194AC_LANG_POP 195 196]) dnl end AC_DEFUN 197