[xml] autoconf patches to 2.4.2 (determine socklen_t type)



The current autoconf code to determine the socklen_t type is icky.
Relying on a return error from the compiler doesn't seem so robust to
me (in all fairness though the patch below requires the compiler to be
smart enough to error out when two prototype declarations don't
match). So, I suggest the attached patch. NOTE: this depends on
autoconf 2.52 (2.50 will probably work). I could get it working under
2.13 if need be. You will need to regenerate config.h.in. I am trying
to get the same socklen_t detection into rsync (which switched to
autoconf 2.50 hence the dependency). This patch has been tested on
Solaris 2.5.1, 2.6, 7, 8, IRIX 6.2, 6.5, Tru64 UNIX 4.0D, 5.0A, 5.1,
HP-UX 10.20, 11.00, and AIX 4.3.2 with success.

-- 
albert chin (china thewrittenword com)

-- snip snip
--- acinclude.m4.orig   Fri Jan  5 00:39:26 2001
+++ acinclude.m4        Thu Aug 16 14:01:19 2001
@@ -1,28 +1,36 @@
-dnl Like AC_TRY_EVAL but also errors out if the compiler generates
-dnl _any_ output. Some compilers might issue warnings which we want
-dnl to catch.
-AC_DEFUN(AC_TRY_EVAL2,
-[{ (eval echo configure:__oline__: \"[$]$1\") 1>&AC_FD_CC; dnl
-(eval [$]$1) 2>&AC_FD_CC; _out=`eval [$]$1 2>&1` && test "x$_out" = x; }])
+AC_DEFUN([TYPE_SOCKLEN_T],
+[
+  AC_CHECK_TYPE([socklen_t], ,[
+    AC_MSG_CHECKING([for socklen_t equivalent])
+    AC_CACHE_VAL([xml_cv_socklen_t_equiv],
+    [
+      # Systems have either "struct sockaddr *" or
+      # "void *" as the second argument to getpeername
+      xml_cv_socklen_t_equiv=
+      for arg2 in "struct sockaddr" void; do
+        for t in int size_t unsigned long "unsigned long"; do
+          AC_TRY_COMPILE([
+            #include <sys/types.h>
+            #include <sys/socket.h>
 
-dnl Like AC_TRY_COMPILE but calls AC_TRY_EVAL2 instead of AC_TRY_EVAL
-AC_DEFUN(AC_TRY_COMPILE2,
-[cat > conftest.$ac_ext <<EOF
-[#]line __oline__ "configure"
-#include "confdefs.h"
-[$1]
-int main() {
-[$2]
-; return 0; }
-EOF
-if AC_TRY_EVAL2(ac_compile); then
-  ifelse([$3], , :, [rm -rf conftest*
-  $3])
-else
-  echo "configure: failed program was:" >&AC_FD_CC
-  cat conftest.$ac_ext >&AC_FD_CC
-ifelse([$4], , , [  rm -rf conftest*
-  $4
-])dnl
-fi
-rm -f conftest*])
+            int getpeername (int, $arg2 *, $t *);
+          ],[
+            $t len;
+            getpeername(0,0,&len);
+          ],[
+            xml_cv_socklen_t_equiv="$t"
+            break
+          ])
+        done
+      done
+
+      if test "x$xml_cv_socklen_t_equiv" = x; then
+        AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
+      fi
+    ])
+    AC_MSG_RESULT($xml_cv_socklen_t_equiv)
+    AC_DEFINE_UNQUOTED(socklen_t, $xml_cv_socklen_t_equiv,
+                      [type to use in place of socklen_t if not defined])],
+    [#include <sys/types.h>
+#include <sys/socket.h>])
+])
--- configure.in.orig   Thu Aug 16 13:44:10 2001
+++ configure.in        Thu Aug 16 14:01:37 2001
@@ -108,32 +103,7 @@
 AC_CHECK_FUNC(gethostent, , AC_CHECK_LIB(nsl, gethostent))
 AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))
 AC_CHECK_FUNC(connect, , AC_CHECK_LIB(inet, connect))
-
-dnl Determine what socket length (socklen_t) data type is
-AC_MSG_CHECKING([for type of socket length (socklen_t)])
-AC_TRY_COMPILE2([
-#include <stddef.h>
-#include <sys/types.h>
-#include <sys/socket.h>],[
-(void)getsockopt (1, 1, 1, NULL, (socklen_t *)NULL)],[
-  AC_MSG_RESULT(socklen_t *)
-  SOCKLEN_T=socklen_t],[
-  AC_TRY_COMPILE2([
-#include <stddef.h>
-#include <sys/types.h>
-#include <sys/socket.h>],[
-(void)getsockopt (1, 1, 1, NULL, (size_t *)NULL)],[
-    AC_MSG_RESULT(size_t *)
-    SOCKLEN_T=size_t],[
-    AC_TRY_COMPILE2([
-#include <stddef.h>
-#include <sys/types.h>
-#include <sys/socket.h>],[
-(void)getsockopt (1, 1, 1, NULL, (int *)NULL)],[
-      AC_MSG_RESULT(int *)
-      SOCKLEN_T=int],[
-      AC_MSG_WARN(could not determine)])])])
-AC_DEFINE_UNQUOTED(SOCKLEN_T, $SOCKLEN_T)
+TYPE_SOCKLEN_T
 
 dnl Checks for isnan in libm if not in libc
 AC_CHECK_FUNC(isnan, , AC_CHECK_LIB(m, isnan,
--- acconfig.h.orig     Thu Aug 16 13:54:26 2001
+++ acconfig.h  Thu Aug 16 13:54:32 2001
@@ -6,4 +6,3 @@
 #undef HAVE_ISNAN
 #undef HAVE_LIBHISTORY
 #undef HAVE_LIBREADLINE
-#undef SOCKLEN_T
--- nanoftp.c.orig      Thu Aug 16 13:59:43 2001
+++ nanoftp.c   Thu Aug 16 13:59:55 2001
@@ -1218,7 +1218,7 @@
     unsigned char ad[6], *adp, *portp;
     unsigned int temp[6];
     struct sockaddr_in dataAddr;
-    SOCKLEN_T dataAddrLen;
+    socklen_t dataAddrLen;
 
 retry:
     ctxt->dataFd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
--- nanohttp.c.orig     Thu Aug 16 13:59:46 2001
+++ nanohttp.c  Thu Aug 16 14:00:10 2001
@@ -59,7 +59,7 @@
 
 #ifdef VMS
 #include <stropts>
-#define SOCKLEN_T unsigned int
+typedef unsigned int socklen_t
 #define SOCKET int
 #endif
 
@@ -789,7 +789,7 @@
     }
 
     if ( FD_ISSET(s, &wfd) ) {
-       SOCKLEN_T len;
+       socklen_t len;
        len = sizeof(status);
        if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char*)&status, &len) < 0 ) {
            /* Solaris error code */




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]