Imported Upstream version 2.6.0p2
[debian/amanda] / config / amanda / socklen_t_equiv.m4
1 # SYNOPSIS
2 #
3 #   AMANDA_SOCKLEN_T_EQUIV
4 #
5 # OVERVIEW
6 #
7 #   Find a type which will work like socklen_t should.  Unfortunately, 
8 #   HP/UX systems define socklen_t, but use int * as the result parameter
9 #   for socket functions returning a socket length.
10 #
11 #   This check defines a type socklen_t_equiv which is of the appropriate
12 #   size to be used with socket functions.
13 #
14 AC_DEFUN([AMANDA_SOCKLEN_T_EQUIV],
15 [
16       ## lifted from config/gnulib/socklen.m4
17       AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl
18       AC_MSG_CHECKING([for socklen_t equivalent])
19       AC_CACHE_VAL([gl_cv_socklen_t_equiv],
20         [# Systems have either "struct sockaddr *" or
21          # "void *" as the second argument to getpeername
22          gl_cv_socklen_t_equiv=
23          for arg2 in "struct sockaddr" void; do
24            for t in socklen_t int size_t "unsigned int" "long int" "unsigned long int"; do
25              AC_TRY_COMPILE(
26                [#include <sys/types.h>
27                 #include <sys/socket.h>
28
29                 int getpeername (int, $arg2 *, $t *);],
30                [$t len;
31                 getpeername (0, 0, &len);],
32                [gl_cv_socklen_t_equiv="$t"])
33              test "$gl_cv_socklen_t_equiv" != "" && break
34            done
35            test "$gl_cv_socklen_t_equiv" != "" && break
36          done
37       ])
38       ## end lifting from config/gnulib/socklen.m4
39       # fallback if the check fails
40       if test "$gl_cv_socklen_t_equiv" = ""; then
41         gl_cv_socklen_t_equiv=socklen_t
42       fi
43       AC_MSG_RESULT([$gl_cv_socklen_t_equiv])
44
45       AC_DEFINE_UNQUOTED([socklen_t_equiv], [$gl_cv_socklen_t_equiv],
46         [type to use for socket length parameters; use instead of socklen_t])
47 ])
48