check for socket() and closesocket() as it is done for other functions
authorYang Tse <yangsita@gmail.com>
Wed, 17 Jun 2009 09:12:19 +0000 (09:12 +0000)
committerYang Tse <yangsita@gmail.com>
Wed, 17 Jun 2009 09:12:19 +0000 (09:12 +0000)
configure.ac
m4/curl-functions.m4

index 1b45233..4643110 100644 (file)
@@ -1999,6 +1999,7 @@ CURL_CHECK_FUNC_SEND
 CURL_CHECK_MSG_NOSIGNAL
 
 CURL_CHECK_FUNC_ALARM
+CURL_CHECK_FUNC_CLOSESOCKET
 CURL_CHECK_FUNC_FCNTL
 CURL_CHECK_FUNC_FDOPEN
 CURL_CHECK_FUNC_FREEADDRINFO
@@ -2026,6 +2027,7 @@ CURL_CHECK_FUNC_SIGACTION
 CURL_CHECK_FUNC_SIGINTERRUPT
 CURL_CHECK_FUNC_SIGNAL
 CURL_CHECK_FUNC_SIGSETJMP
+CURL_CHECK_FUNC_SOCKET
 CURL_CHECK_FUNC_STRCASECMP
 CURL_CHECK_FUNC_STRCASESTR
 CURL_CHECK_FUNC_STRCMPI
@@ -2054,7 +2056,6 @@ case $host in
 esac
 
 AC_CHECK_FUNCS([basename \
-  closesocket \
   fork \
   geteuid \
   getpass_r \
@@ -2069,7 +2070,6 @@ AC_CHECK_FUNCS([basename \
   setlocale \
   setmode \
   setrlimit \
-  socket \
   uname \
   utime
 ],[
index 3523730..c2f446a 100644 (file)
@@ -22,7 +22,7 @@
 #***************************************************************************
 
 # File version for 'aclocal' use. Keep it a single number.
-# serial 47
+# serial 48
 
 
 dnl CURL_INCLUDES_ARPA_INET
@@ -577,6 +577,96 @@ AC_DEFUN([CURL_CHECK_FUNC_ALARM], [
 ])
 
 
+dnl CURL_CHECK_FUNC_CLOSESOCKET
+dnl -------------------------------------------------
+dnl Verify if closesocket is available, prototyped, and
+dnl can be compiled. If all of these are true, and
+dnl usage has not been previously disallowed with
+dnl shell variable curl_disallow_closesocket, then
+dnl HAVE_CLOSESOCKET will be defined.
+
+AC_DEFUN([CURL_CHECK_FUNC_CLOSESOCKET], [
+  AC_REQUIRE([CURL_INCLUDES_WINSOCK2])dnl
+  #
+  tst_links_closesocket="unknown"
+  tst_proto_closesocket="unknown"
+  tst_compi_closesocket="unknown"
+  tst_allow_closesocket="unknown"
+  #
+  AC_MSG_CHECKING([if closesocket can be linked])
+  AC_LINK_IFELSE([
+    AC_LANG_PROGRAM([[
+      $curl_includes_winsock2
+    ]],[[
+      if(0 != closesocket(0))
+        return 1;
+    ]])
+  ],[
+    AC_MSG_RESULT([yes])
+    tst_links_closesocket="yes"
+  ],[
+    AC_MSG_RESULT([no])
+    tst_links_closesocket="no"
+  ])
+  #
+  if test "$tst_links_closesocket" = "yes"; then
+    AC_MSG_CHECKING([if closesocket is prototyped])
+    AC_EGREP_CPP([closesocket],[
+      $curl_includes_winsock2
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_proto_closesocket="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_proto_closesocket="no"
+    ])
+  fi
+  #
+  if test "$tst_proto_closesocket" = "yes"; then
+    AC_MSG_CHECKING([if closesocket is compilable])
+    AC_COMPILE_IFELSE([
+      AC_LANG_PROGRAM([[
+        $curl_includes_winsock2
+      ]],[[
+        if(0 != closesocket(0))
+          return 1;
+      ]])
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_compi_closesocket="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_compi_closesocket="no"
+    ])
+  fi
+  #
+  if test "$tst_compi_closesocket" = "yes"; then
+    AC_MSG_CHECKING([if closesocket usage allowed])
+    if test "x$curl_disallow_closesocket" != "xyes"; then
+      AC_MSG_RESULT([yes])
+      tst_allow_closesocket="yes"
+    else
+      AC_MSG_RESULT([no])
+      tst_allow_closesocket="no"
+    fi
+  fi
+  #
+  AC_MSG_CHECKING([if closesocket might be used])
+  if test "$tst_links_closesocket" = "yes" &&
+     test "$tst_proto_closesocket" = "yes" &&
+     test "$tst_compi_closesocket" = "yes" &&
+     test "$tst_allow_closesocket" = "yes"; then
+    AC_MSG_RESULT([yes])
+    AC_DEFINE_UNQUOTED(HAVE_CLOSESOCKET, 1,
+      [Define to 1 if you have the closesocket function.])
+    ac_cv_func_closesocket="yes"
+  else
+    AC_MSG_RESULT([no])
+    ac_cv_func_closesocket="no"
+  fi
+])
+
+
 dnl CURL_CHECK_FUNC_FCNTL
 dnl -------------------------------------------------
 dnl Verify if fcntl is available, prototyped, and
@@ -3830,6 +3920,100 @@ AC_DEFUN([CURL_CHECK_FUNC_SIGSETJMP], [
 ])
 
 
+dnl CURL_CHECK_FUNC_SOCKET
+dnl -------------------------------------------------
+dnl Verify if socket is available, prototyped, and
+dnl can be compiled. If all of these are true, and
+dnl usage has not been previously disallowed with
+dnl shell variable curl_disallow_socket, then
+dnl HAVE_SOCKET will be defined.
+
+AC_DEFUN([CURL_CHECK_FUNC_SOCKET], [
+  AC_REQUIRE([CURL_INCLUDES_WINSOCK2])dnl
+  AC_REQUIRE([CURL_INCLUDES_SYS_SOCKET])dnl
+  #
+  tst_links_socket="unknown"
+  tst_proto_socket="unknown"
+  tst_compi_socket="unknown"
+  tst_allow_socket="unknown"
+  #
+  AC_MSG_CHECKING([if socket can be linked])
+  AC_LINK_IFELSE([
+    AC_LANG_PROGRAM([[
+      $curl_includes_winsock2
+      $curl_includes_sys_socket
+    ]],[[
+      if(0 != socket(0, 0, 0))
+        return 1;
+    ]])
+  ],[
+    AC_MSG_RESULT([yes])
+    tst_links_socket="yes"
+  ],[
+    AC_MSG_RESULT([no])
+    tst_links_socket="no"
+  ])
+  #
+  if test "$tst_links_socket" = "yes"; then
+    AC_MSG_CHECKING([if socket is prototyped])
+    AC_EGREP_CPP([socket],[
+      $curl_includes_winsock2
+      $curl_includes_sys_socket
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_proto_socket="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_proto_socket="no"
+    ])
+  fi
+  #
+  if test "$tst_proto_socket" = "yes"; then
+    AC_MSG_CHECKING([if socket is compilable])
+    AC_COMPILE_IFELSE([
+      AC_LANG_PROGRAM([[
+        $curl_includes_winsock2
+        $curl_includes_sys_socket
+      ]],[[
+        if(0 != socket(0, 0, 0))
+          return 1;
+      ]])
+    ],[
+      AC_MSG_RESULT([yes])
+      tst_compi_socket="yes"
+    ],[
+      AC_MSG_RESULT([no])
+      tst_compi_socket="no"
+    ])
+  fi
+  #
+  if test "$tst_compi_socket" = "yes"; then
+    AC_MSG_CHECKING([if socket usage allowed])
+    if test "x$curl_disallow_socket" != "xyes"; then
+      AC_MSG_RESULT([yes])
+      tst_allow_socket="yes"
+    else
+      AC_MSG_RESULT([no])
+      tst_allow_socket="no"
+    fi
+  fi
+  #
+  AC_MSG_CHECKING([if socket might be used])
+  if test "$tst_links_socket" = "yes" &&
+     test "$tst_proto_socket" = "yes" &&
+     test "$tst_compi_socket" = "yes" &&
+     test "$tst_allow_socket" = "yes"; then
+    AC_MSG_RESULT([yes])
+    AC_DEFINE_UNQUOTED(HAVE_SOCKET, 1,
+      [Define to 1 if you have the socket function.])
+    ac_cv_func_socket="yes"
+  else
+    AC_MSG_RESULT([no])
+    ac_cv_func_socket="no"
+  fi
+])
+
+
 dnl CURL_CHECK_FUNC_STRCASECMP
 dnl -------------------------------------------------
 dnl Verify if strcasecmp is available, prototyped, and