declare smobs in alloc.c
[bpt/emacs.git] / m4 / socklen.m4
CommitLineData
6a90a4f1 1# socklen.m4 serial 10
ba318903 2dnl Copyright (C) 2005-2007, 2009-2014 Free Software Foundation, Inc.
401bf9b4
PE
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Albert Chin, Windows fixes from Simon Josefsson.
8
9dnl Check for socklen_t: historically on BSD it is an int, and in
10dnl POSIX 1g it is a type of its own, but some platforms use different
11dnl types for the argument to getsockopt, getpeername, etc.:
6a90a4f1 12dnl HP-UX 10.20, IRIX 6.5, OSF/1 4.0, Interix 3.5, BeOS.
401bf9b4
PE
13dnl So we have to test to find something that will work.
14
401bf9b4 15AC_DEFUN([gl_TYPE_SOCKLEN_T],
6a90a4f1 16 [AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])dnl
401bf9b4
PE
17 AC_CHECK_TYPE([socklen_t], ,
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 int size_t "unsigned int" "long int" "unsigned long int"; do
25 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
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 if test "$gl_cv_socklen_t_equiv" = ""; then
39 AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
40 fi
41 AC_MSG_RESULT([$gl_cv_socklen_t_equiv])
42 AC_DEFINE_UNQUOTED([socklen_t], [$gl_cv_socklen_t_equiv],
43 [type to use in place of socklen_t if not defined])],
6a90a4f1
PE
44 [gl_SOCKET_HEADERS])])
45
46dnl On mingw32, socklen_t is in ws2tcpip.h ('int'), so we try to find
47dnl it there too. But on Cygwin, wc2tcpip.h must not be included. Users
48dnl of this module should use the same include pattern as gl_SOCKET_HEADERS.
49dnl When you change this macro, keep also in sync:
50dnl - gl_CHECK_SOCKET_HEADERS,
51dnl - the Include section of modules/socklen.
52AC_DEFUN([gl_SOCKET_HEADERS],
53[
54/* <sys/types.h> is not needed according to POSIX, but the
55 <sys/socket.h> in i386-unknown-freebsd4.10 and
56 powerpc-apple-darwin5.5 required it. */
57#include <sys/types.h>
58#if HAVE_SYS_SOCKET_H
59# include <sys/socket.h>
60#elif HAVE_WS2TCPIP_H
61# include <ws2tcpip.h>
62#endif
63])
401bf9b4 64
6a90a4f1
PE
65dnl Tests for the existence of the header for socket facilities.
66dnl Defines the C macros HAVE_SYS_SOCKET_H, HAVE_WS2TCPIP_H.
67dnl This macro must match gl_SOCKET_HEADERS.
68AC_DEFUN([gl_CHECK_SOCKET_HEADERS],
401bf9b4 69 [AC_CHECK_HEADERS_ONCE([sys/socket.h])
6a90a4f1
PE
70 if test $ac_cv_header_sys_socket_h = no; then
71 dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
72 dnl the check for those headers unconditional; yet cygwin reports
73 dnl that the headers are present but cannot be compiled (since on
74 dnl cygwin, all socket information should come from sys/socket.h).
75 AC_CHECK_HEADERS([ws2tcpip.h])
76 fi
77 ])