passfd: allow compilation on mingw
[gnulib.git] / m4 / afunix.m4
1 # afunix.m4 serial 7
2 dnl Copyright (C) 2011 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_SOCKET_AFUNIX],
8 [
9   AC_REQUIRE([gl_HEADER_SYS_SOCKET])
10   AC_REQUIRE([gl_SOCKET_FAMILY_UNIX])
11   AC_CHECK_FUNCS_ONCE([recvmsg sendmsg])
12
13   AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHTS])
14   AC_CACHE_VAL([gl_cv_socket_unix_scm_rights],
15     [AC_COMPILE_IFELSE(
16        [AC_LANG_PROGRAM(
17           [[#include <sys/types.h>
18             #ifdef HAVE_SYS_SOCKET_H
19             #include <sys/socket.h>
20             #endif
21             #ifdef HAVE_SYS_UN_H
22             #include <sys/un.h>
23             #endif
24             #ifdef HAVE_WINSOCK2_H
25             #include <winsock2.h>
26             #endif
27           ]],
28           [[struct cmsghdr cmh;
29             cmh.cmsg_level = SOL_SOCKET;
30             cmh.cmsg_type = SCM_RIGHTS;
31             if (&cmh) return 0;
32           ]])],
33        [gl_cv_socket_unix_scm_rights=yes],
34        [gl_cv_socket_unix_scm_rights=no])
35     ])
36   AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights])
37   if test $gl_cv_socket_unix_scm_rights = yes; then
38     AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS], [1],
39       [Define to 1 if <sys/socket.h> defines SCM_RIGHTS.])
40   fi
41
42   dnl Persuade AIX 5.2 <sys/socket.h> to declare CMSG_SPACE, CMSG_LEN.
43   AC_DEFINE([_LINUX_SOURCE_COMPAT], [1],
44     [Define in order to get some macros on AIX systems.])
45
46   AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHTS that behave in BSD4.4 way])
47   AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd44_way],
48     [AC_COMPILE_IFELSE(
49        [AC_LANG_PROGRAM(
50           [[#include <sys/types.h>
51             #include <stddef.h>
52             #ifdef HAVE_SYS_SOCKET_H
53             #include <sys/socket.h>
54             #endif
55             #ifdef HAVE_SYS_UN_H
56             #include <sys/un.h>
57             #endif
58             #ifdef HAVE_WINSOCK2_H
59             #include <winsock2.h>
60             #endif
61             ]],
62             [[struct msghdr msg = {0};
63               struct cmsghdr *cmsg;
64               int myfds[1] = {0};
65               char buf[CMSG_SPACE (sizeof (myfds))];
66
67               msg.msg_control = buf;
68               msg.msg_controllen = sizeof buf;
69               cmsg = CMSG_FIRSTHDR (&msg);
70               cmsg->cmsg_level = SOL_SOCKET;
71               cmsg->cmsg_type = SCM_RIGHTS;
72               cmsg->cmsg_len = CMSG_LEN (sizeof (int));
73               /* fake Initialize the payload: */
74               (void) CMSG_DATA (cmsg);
75               /* Sum of the length of all control messages in the buffer: */
76               msg.msg_controllen = cmsg->cmsg_len;
77               return 0;
78             ]])],
79        [gl_cv_socket_unix_scm_rights_bsd44_way=yes],
80        [gl_cv_socket_unix_scm_rights_bsd44_way=no])
81     ])
82   AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights_bsd44_way])
83   if test $gl_cv_socket_unix_scm_rights_bsd44_way = yes; then
84     AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY], [1],
85       [Define to 1 if fd can be sent/received in the BSD4.4 way.])
86   fi
87
88   AC_MSG_CHECKING([for UNIX domain sockets SCM_RIGHTS that behave in BSD4.3 way])
89   AC_CACHE_VAL([gl_cv_socket_unix_scm_rights_bsd43_way],
90     [AC_COMPILE_IFELSE(
91        [AC_LANG_PROGRAM(
92           [[#include <sys/types.h>
93             #ifdef HAVE_SYS_SOCKET_H
94             #include <sys/socket.h>
95             #endif
96             #ifdef HAVE_SYS_UN_H
97             #include <sys/un.h>
98             #endif
99             #ifdef HAVE_WINSOCK2_H
100             #include <winsock2.h>
101             #endif
102             ]],
103             [[struct msghdr msg;
104               int fd = 0;
105               msg.msg_accrights = &fd;
106               msg.msg_accrightslen = sizeof (fd);
107               if (&msg) return 0;
108             ]])],
109        [gl_cv_socket_unix_scm_rights_bsd43_way=yes],
110        [gl_cv_socket_unix_scm_rights_bsd43_way=no])
111     ])
112   AC_MSG_RESULT([$gl_cv_socket_unix_scm_rights_bsd43_way])
113   if test $gl_cv_socket_unix_scm_rights_bsd43_way = yes; then
114     AC_DEFINE([HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY], [1],
115       [Define to 1 if fd can be sent/received in the BSD4.3 way.])
116   fi
117 ])