improve detection of getservbyport_r()
authorYang Tse <yangsita@gmail.com>
Wed, 17 Sep 2008 11:31:37 +0000 (11:31 +0000)
committerYang Tse <yangsita@gmail.com>
Wed, 17 Sep 2008 11:31:37 +0000 (11:31 +0000)
acinclude.m4
ares_getnameinfo.c
configure.ac
m4/cares-functions.m4

index 9cb54ae..46b087c 100644 (file)
@@ -2027,132 +2027,3 @@ AC_DEFUN([CARES_CHECK_CONSTANT], [
   fi
 ])
 
-
-dnl CARES_CHECK_GETSERVBYPORT_R
-dnl -------------------------------------------------
-dnl Test if the getservbyport_r function is available,
-dnl and find out how many parameters it takes.
-
-AC_DEFUN([CARES_CHECK_GETSERVBYPORT_R], [
-  AC_CHECK_HEADERS(sys/types.h netdb.h)
-  #
-  AC_MSG_CHECKING([for getservbyport_r])
-  AC_LINK_IFELSE([
-    AC_LANG_FUNC_LINK_TRY([getservbyport_r])
-  ],[
-    AC_MSG_RESULT([yes])
-    cares_cv_getservbyport_r="yes"
-  ],[
-    AC_MSG_RESULT([no])
-    cares_cv_getservbyport_r="no"
-  ])
-  #
-  if test "$cares_cv_getservbyport_r" != "yes"; then
-    AC_MSG_CHECKING([deeper for getservbyport_r])
-    AC_LINK_IFELSE([
-      AC_LANG_PROGRAM([[
-      ]],[[
-        getservbyport_r();
-      ]])
-    ],[
-      AC_MSG_RESULT([yes])
-      cares_cv_getservbyport_r="yes"
-    ],[
-      AC_MSG_RESULT([but still no])
-      cares_cv_getservbyport_r="no"
-    ])
-  fi
-  #
-  if test "$cares_cv_getservbyport_r" = "yes"; then
-    AC_MSG_CHECKING([how many arguments getservbyport_r takes])
-    cares_cv_getservbyport_r_nargs="unknown"
-    #
-    AC_COMPILE_IFELSE([
-      AC_LANG_PROGRAM([[
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-        extern int
-        getservbyport_r(int, const char*, struct servent*,
-                        char*, size_t, struct servent**);
-      ]],[[
-        int p1, res;
-        size_t p5;
-        char *p2, p4[4096];
-        struct servent *p3, *p6;
-        res = getservbyport_r(p1, p2, p3, p4, p5, &p6);
-      ]])
-    ],[
-      cares_cv_getservbyport_r_nargs="6"
-    ])
-    #
-    if test "$cares_cv_getservbyport_r_nargs" = "unknown"; then
-      AC_COMPILE_IFELSE([
-        AC_LANG_PROGRAM([[
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-          extern struct servent*
-          getservbyport_r(int, const char*, struct servent*,
-                          char*, int);
-        ]],[[
-          int p1, p5;
-          char *p2, p4[4096];
-          struct servent *p3, res;
-          res = getservbyport_r(p1, p2, p3, p4, p5);
-        ]])
-      ],[
-        cares_cv_getservbyport_r_nargs="5"
-      ])
-    fi
-    #
-    if test "$cares_cv_getservbyport_r_nargs" = "unknown"; then
-      AC_COMPILE_IFELSE([
-        AC_LANG_PROGRAM([[
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-          extern int
-          getservbyport_r(int, const char*, struct servent*,
-                          struct servent_data*);
-        ]],[[
-          int p1, res;
-          char *p2;
-          struct servent *p3;
-          struct servent_data *p4;
-          res = getservbyport_r(p1, p2, p3, p4);
-        ]])
-      ],[
-        cares_cv_getservbyport_r_nargs="4"
-      ])
-    fi
-    #
-    AC_MSG_RESULT([$cares_cv_getservbyport_r_nargs])
-    #
-    if test "$cares_cv_getservbyport_r_nargs" = "unknown"; then
-      AC_MSG_WARN([HAVE_GETSERVBYPORT_R will not be defined])
-    else
-      AC_DEFINE(HAVE_GETSERVBYPORT_R, 1,
-        [Specifies whether getservbyport_r is present])
-      AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $cares_cv_getservbyport_r_nargs,
-        [Specifies the number of arguments to getservbyport_r])
-      if test "$cares_cv_getservbyport_r_nargs" = "4" ; then
-        AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data),
-          [Specifies the size of the buffer to pass to getservbyport_r])
-      else
-        AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096,
-          [Specifies the size of the buffer to pass to getservbyport_r])
-      fi
-    fi
-    #
-  fi
-])
index 99d3b87..7bd4eca 100644 (file)
  */
 #include "setup.h"
 
+#ifdef HAVE_GETSERVBYPORT_R
+#  if !defined(GETSERVBYPORT_R_ARGS) || \
+     (GETSERVBYPORT_R_ARGS < 4) || (GETSERVBYPORT_R_ARGS > 6)
+#    error "you MUST specifiy a valid number of arguments for getservbyport_r"
+#  endif
+#endif
+
 #ifdef HAVE_SYS_SOCKET_H
 #  include <sys/socket.h>
 #endif
index 9aacaea..f0e1a04 100644 (file)
@@ -645,6 +645,7 @@ CURL_CHECK_FUNC_SEND
 CURL_CHECK_MSG_NOSIGNAL
 
 CARES_CHECK_FUNC_GETHOSTNAME
+CARES_CHECK_FUNC_GETSERVBYPORT_R
 CARES_CHECK_FUNC_STRCASECMP
 CARES_CHECK_FUNC_STRCMPI
 CARES_CHECK_FUNC_STRDUP
@@ -999,10 +1000,6 @@ dnl and get the types of five of its arguments.
 CURL_CHECK_FUNC_GETNAMEINFO
 
 
-dnl God bless non-standardized functions! We need to see which getservbyport_r
-dnl variant is available
-CARES_CHECK_GETSERVBYPORT_R
-
 CURL_CHECK_NONBLOCKING_SOCKET
 
 AC_C_BIGENDIAN(
index e1ba240..0ba0324 100644 (file)
 #***************************************************************************
 
 # File version for 'aclocal' use. Keep it a single number.
-# serial 1
+# serial 5
+
+
+dnl CARES_INCLUDES_NETDB
+dnl -------------------------------------------------
+dnl Set up variable with list of headers that must be
+dnl included when netdb.h is to be included.
+
+AC_DEFUN([CARES_INCLUDES_NETDB], [
+cares_includes_netdb="\
+/* includes start */
+#ifdef HAVE_SYS_TYPES_H
+#  include <sys/types.h>
+#endif
+#ifdef HAVE_NETDB_H
+#  include <netdb.h>
+#endif
+/* includes end */"
+  AC_CHECK_HEADERS(
+    sys/types.h netdb.h,
+    [], [], [$cares_includes_netdb])
+])
 
 
 dnl CARES_INCLUDES_STRING
@@ -170,6 +191,146 @@ AC_DEFUN([CARES_CHECK_FUNC_GETHOSTNAME], [
 ])
 
 
+dnl CARES_CHECK_FUNC_GETSERVBYPORT_R
+dnl -------------------------------------------------
+dnl Verify if getservbyport_r is available, prototyped,
+dnl and can be compiled. If all of these are true, and
+dnl usage has not been previously disallowed with
+dnl shell variable cares_disallow_getservbyport_r, then
+dnl HAVE_GETSERVBYPORT_R will be defined.
+
+AC_DEFUN([CARES_CHECK_FUNC_GETSERVBYPORT_R], [
+  AC_REQUIRE([CARES_INCLUDES_SYS_UIO])dnl
+  #
+  tst_links_getservbyport_r="unknown"
+  tst_proto_getservbyport_r="unknown"
+  tst_compi_getservbyport_r="unknown"
+  tst_allow_getservbyport_r="unknown"
+  tst_nargs_getservbyport_r="unknown"
+  #
+  AC_MSG_CHECKING([if getservbyport_r can be linked])
+  AC_LINK_IFELSE([
+    AC_LANG_FUNC_LINK_TRY([getservbyport_r])
+  ],[
+    AC_MSG_RESULT([yes])
+    tst_links_getservbyport_r="yes"
+  ],[
+    AC_MSG_RESULT([no])
+    tst_links_getservbyport_r="no"
+  ])
+  #
+  if test "$tst_links_getservbyport_r" = "yes"; then
+    AC_MSG_CHECKING([if getservbyport_r is prototyped])
+    AC_EGREP_CPP([getservbyport_r],[
+      $cares_includes_netdb
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_proto_getservbyport_r="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_proto_getservbyport_r="no"
+    ])
+  fi
+  #
+  if test "$tst_proto_getservbyport_r" = "yes"; then
+    if test "$tst_nargs_getservbyport_r" = "unknown"; then
+      AC_MSG_CHECKING([if getservbyport_r takes 4 args.])
+      AC_COMPILE_IFELSE([
+        AC_LANG_PROGRAM([[
+          $cares_includes_netdb
+        ]],[[
+          if(0 != getservbyport_r(0, 0, 0, 0))
+            return 1;
+        ]])
+      ],[
+        AC_MSG_RESULT([yes])
+        tst_compi_getservbyport_r="yes"
+        tst_nargs_getservbyport_r="4"
+      ],[
+        AC_MSG_RESULT([no])
+        tst_compi_getservbyport_r="no"
+      ])
+    fi
+    if test "$tst_nargs_getservbyport_r" = "unknown"; then
+      AC_MSG_CHECKING([if getservbyport_r takes 5 args.])
+      AC_COMPILE_IFELSE([
+        AC_LANG_PROGRAM([[
+          $cares_includes_netdb
+        ]],[[
+          if(0 != getservbyport_r(0, 0, 0, 0, 0))
+            return 1;
+        ]])
+      ],[
+        AC_MSG_RESULT([yes])
+        tst_compi_getservbyport_r="yes"
+        tst_nargs_getservbyport_r="5"
+      ],[
+        AC_MSG_RESULT([no])
+        tst_compi_getservbyport_r="no"
+      ])
+    fi
+    if test "$tst_nargs_getservbyport_r" = "unknown"; then
+      AC_MSG_CHECKING([if getservbyport_r takes 6 args.])
+      AC_COMPILE_IFELSE([
+        AC_LANG_PROGRAM([[
+          $cares_includes_netdb
+        ]],[[
+          if(0 != getservbyport_r(0, 0, 0, 0, 0, 0))
+            return 1;
+        ]])
+      ],[
+        AC_MSG_RESULT([yes])
+        tst_compi_getservbyport_r="yes"
+        tst_nargs_getservbyport_r="6"
+      ],[
+        AC_MSG_RESULT([no])
+        tst_compi_getservbyport_r="no"
+      ])
+    fi
+    AC_MSG_CHECKING([if getservbyport_r is compilable])
+    if test "$tst_compi_getservbyport_r" = "yes"; then
+      AC_MSG_RESULT([yes])
+    else
+      AC_MSG_RESULT([no])
+    fi
+  fi
+  #
+  if test "$tst_compi_getservbyport_r" = "yes"; then
+    AC_MSG_CHECKING([if getservbyport_r usage allowed])
+    if test "x$cares_disallow_getservbyport_r" != "xyes"; then
+      AC_MSG_RESULT([yes])
+      tst_allow_getservbyport_r="yes"
+    else
+      AC_MSG_RESULT([no])
+      tst_allow_getservbyport_r="no"
+    fi
+  fi
+  #
+  AC_MSG_CHECKING([if getservbyport_r might be used])
+  if test "$tst_links_getservbyport_r" = "yes" &&
+     test "$tst_proto_getservbyport_r" = "yes" &&
+     test "$tst_compi_getservbyport_r" = "yes" &&
+     test "$tst_allow_getservbyport_r" = "yes"; then
+    AC_MSG_RESULT([yes])
+    AC_DEFINE_UNQUOTED(HAVE_GETSERVBYPORT_R, 1,
+      [Define to 1 if you have the getservbyport_r function.])
+    AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $tst_nargs_getservbyport_r,
+      [Specifies the number of arguments to getservbyport_r])
+    if test "$tst_nargs_getservbyport_r" -eq "4"; then
+      AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data),
+        [Specifies the size of the buffer to pass to getservbyport_r])
+    else
+      AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096,
+        [Specifies the size of the buffer to pass to getservbyport_r])
+    fi
+    ac_cv_func_getservbyport_r="yes"
+  else
+    AC_MSG_RESULT([no])
+    ac_cv_func_getservbyport_r="no"
+  fi
+])
+
+
 dnl CARES_CHECK_FUNC_STRCASECMP
 dnl -------------------------------------------------
 dnl Verify if strcasecmp is available, prototyped, and