Browse code

build: m4/ax_socklen_t.m4: cleanup

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Acked-by: David Sommerseth <davids@redhat.com>
Signed-off-by: David Sommerseth <davids@redhat.com>

Alon Bar-Lev authored on 2012/03/01 05:11:55
Showing 2 changed files
... ...
@@ -381,10 +381,10 @@ AC_TYPE_OFF_T
381 381
 AC_TYPE_PID_T
382 382
 AC_TYPE_SIZE_T
383 383
 AC_TYPE_UID_T
384
-TYPE_SOCKLEN_T
385 384
 AC_HEADER_TIME
386 385
 AX_CPP_VARARG_MACRO_ISO
387 386
 AX_CPP_VARARG_MACRO_GCC
387
+AX_TYPE_SOCKLEN_T
388 388
 AX_EMPTY_ARRAY
389 389
 
390 390
 dnl Check for more header files.
... ...
@@ -1,50 +1,65 @@
1
-dnl -- The following is taken from curl's acinclude.m4 --
1
+dnl -- The following is base of curl's acinclude.m4 --
2 2
 dnl Check for socklen_t: historically on BSD it is an int, and in
3 3
 dnl POSIX 1g it is a type of its own, but some platforms use different
4 4
 dnl types for the argument to getsockopt, getpeername, etc.  So we
5 5
 dnl have to test to find something that will work.
6
-AC_DEFUN([TYPE_SOCKLEN_T],
7
-[
8
-   AC_CHECK_TYPE([socklen_t], ,[
9
-      AC_MSG_CHECKING([for socklen_t equivalent])
10
-      AC_CACHE_VAL([curl_cv_socklen_t_equiv],
11
-      [
12
-         case "$host" in
13
-	 *-mingw*) curl_cv_socklen_t_equiv=int ;;
14
-	 *)
15
-            # Systems have either "struct sockaddr *" or
16
-            # "void *" as the second argument to getpeername
17
-            curl_cv_socklen_t_equiv=
18
-            for arg2 in "struct sockaddr" void; do
19
-               for t in int size_t unsigned long "unsigned long"; do
20
-                  AC_TRY_COMPILE([
21
-                     #include <sys/types.h>
22
-                     #include <sys/socket.h>
23
-
24
-                     int getpeername (int, $arg2 *, $t *);
25
-                  ],[
26
-                     $t len;
27
-                     getpeername(0,0,&len);
28
-                  ],[
29
-                     curl_cv_socklen_t_equiv="$t"
30
-                     break
31
-                  ])
32
-               done
33
-            done
34
-	 ;;
35
-	 esac
36
-
37
-         if test "x$curl_cv_socklen_t_equiv" = x; then
38
-            AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
39
-         fi
40
-      ])
41
-      AC_MSG_RESULT($curl_cv_socklen_t_equiv)
42
-      AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
43
-			[type to use in place of socklen_t if not defined])],
44
-      [#include <sys/types.h>
6
+AC_DEFUN([AX_TYPE_SOCKLEN_T], [
7
+	AC_CHECK_TYPE(
8
+		[socklen_t],
9
+		,
10
+		[
11
+			AS_VAR_PUSHDEF([VAR],[ax_cv_socklen_t_equiv])dnl
12
+			AC_CACHE_CHECK(
13
+				[for socklen_t equivalent],
14
+				[VAR],
15
+				[
16
+					#AS_CASE is not supported on <autoconf-2.60
17
+					case "${host}" in
18
+					*-mingw*) VAR=int ;;
19
+					*)
20
+						# Systems have either "struct sockaddr *" or
21
+						# "void *" as the second argument to getpeername
22
+						for arg2 in "struct sockaddr" void; do
23
+							for t in int size_t unsigned long "unsigned long"; do
24
+								AC_COMPILE_IFELSE(
25
+									[AC_LANG_PROGRAM(
26
+										[[
27
+#include <sys/types.h>
28
+#include <sys/socket.h>
29
+int getpeername (int, $arg2 *, $t *);
30
+										]],
31
+										[[
32
+$t len;
33
+getpeername(0,0,&len);
34
+										]]
35
+									)],
36
+									[VAR="$t"; break]
37
+								)
38
+							done
39
+							test -n "$VAR" && break
40
+						done
41
+						;;
42
+					esac
43
+				]
44
+				AS_VAR_IF(
45
+					[VAR],
46
+					[],
47
+					[AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])],
48
+					[AC_DEFINE_UNQUOTED(
49
+						[socklen_t],
50
+						[$VAR],
51
+						[type to use in place of socklen_t if not defined]
52
+					)]
53
+				)
54
+			)
55
+		],
56
+		[[
57
+#include <sys/types.h>
45 58
 #ifdef WIN32
46 59
 #include <ws2tcpip.h>
47 60
 #else
48 61
 #include <sys/socket.h>
49
-#endif])
62
+#endif
63
+		]]
64
+	)
50 65
 ])