package upload
[framework/uifw/ecore.git] / m4 / ac_abstract_socket.m4
1 dnl AC_ABSTRACT_SOCKET_TEST(ACTION_IF_FOUND, ACTION_IF_NOT_FOUND)
2 dnl test if a system supports the abstract socket namespace
3 dnl by rephorm
4 AC_DEFUN([AC_ABSTRACT_SOCKET_TEST], [
5 AC_MSG_CHECKING(abstract sockets)
6 AC_LANG_PUSH(C)
7 AC_RUN_IFELSE([AC_LANG_PROGRAM(
8 [[
9 // headers
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <sys/socket.h>
14 #include <sys/types.h>
15 #include <sys/un.h>
16 ]],
17 [[
18 // main fn
19 #define ABS_SUN_LEN(s, path) (strlen(path) + 1 + (size_t)(((struct sockaddr_un *)NULL)->sun_path))
20   int fd;
21   struct sockaddr_un sock;
22   char *tmp;
23   char *name = "/ecore/dbus/abstract/test";
24
25   sock.sun_family = AF_UNIX;
26   snprintf(sock.sun_path, sizeof(sock.sun_path), ".%s", name);
27   sock.sun_path[0] = '\0';
28         fd = socket(PF_UNIX, SOCK_STREAM, 0);
29   if (bind(fd, (struct sockaddr *)&sock, ABS_SUN_LEN(&sock, name)) < 0)
30   {
31     printf("Failed to bind to abstract socket.\n");
32     exit(1);
33   }
34
35   printf ("connected\n");
36   exit(0);
37 ]])],
38 [$1],
39 [$2])
40 ])
41