maint: update almost all copyright ranges to include 2011
[gnulib.git] / m4 / getdomainname.m4
1 # getdomainname.m4 serial 5
2 dnl Copyright (C) 2002-2003, 2008-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_FUNC_GETDOMAINNAME],
8 [
9   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10   AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H
11   AC_REQUIRE([gl_HEADER_NETDB])dnl for HAVE_NETDB_H
12
13   dnl Persuade glibc <unistd.h> to declare getdomainname().
14   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
15
16   dnl Where is getdomainname() defined?
17   dnl - On Solaris, it is in libnsl. But this function is not declared and
18   dnl   is discouraged, see
19   dnl   <http://www.sun.com/software/solaris/programs/abi/appcert_faq.xml#q18>.
20   dnl   We need to avoid a collision with this function.
21   dnl - Otherwise is is in libc.
22   AC_CHECK_FUNCS([getdomainname], , [
23     AC_CACHE_CHECK([for getdomainname in -lnsl],
24       [gl_cv_func_getdomainname_in_libnsl],
25       [gl_cv_func_getdomainname_in_libnsl=no
26        gl_save_LIBS="$LIBS"
27        LIBS="$LIBS -lnsl"
28        AC_LINK_IFELSE(
29          [AC_LANG_PROGRAM(
30             [[#include <stddef.h>
31               extern int getdomainname (char *, size_t);
32             ]],
33             [[getdomainname(NULL, 0);]])],
34          [gl_cv_func_getdomainname_in_libnsl=yes])
35        LIBS="$gl_save_LIBS"
36       ])
37   ])
38
39   dnl What about the declaration?
40   dnl - It's  int getdomainname(char *, size_t)  on glibc, NetBSD, OpenBSD.
41   dnl - It's  int getdomainname(char *, int)  on MacOS X, FreeBSD, AIX, IRIX,
42   dnl   OSF/1.
43   AC_CHECK_DECLS([getdomainname], , ,
44     [#include <sys/types.h>
45      #ifdef HAVE_SYS_SOCKET_H
46      #include <sys/socket.h>
47      #endif
48      #ifdef HAVE_NETDB_H
49      #include <netdb.h>
50      #endif
51      #include <unistd.h>
52     ])
53   AC_CACHE_CHECK([for getdomainname's second argument type],
54     [gl_cv_decl_getdomainname_argtype2],
55     [if test $ac_cv_have_decl_getdomainname; then
56        AC_COMPILE_IFELSE(
57          [AC_LANG_PROGRAM(
58             [[#include <sys/types.h>
59               #ifdef HAVE_SYS_SOCKET_H
60               #include <sys/socket.h>
61               #endif
62               #ifdef HAVE_NETDB_H
63               #include <netdb.h>
64               #endif
65               #include <unistd.h>
66               extern int getdomainname (char *, int);]],
67             [[]])],
68          [gl_cv_decl_getdomainname_argtype2='int'],
69          [gl_cv_decl_getdomainname_argtype2='size_t'])
70      else
71        gl_cv_decl_getdomainname_argtype2='int'
72      fi
73     ])
74
75   if test $ac_cv_have_decl_getdomainname = no; then
76     HAVE_DECL_GETDOMAINNAME=0
77   fi
78
79   if { test $ac_cv_func_getdomainname = yes \
80        && test $gl_cv_decl_getdomainname_argtype2 != size_t; \
81      } \
82      || test "$gl_cv_func_getdomainname_in_libnsl" = yes; then
83     REPLACE_GETDOMAINNAME=1
84   fi
85
86   if test $HAVE_DECL_GETDOMAINNAME = 0 || test $REPLACE_GETDOMAINNAME = 1; then
87     AC_LIBOBJ([getdomainname])
88     gl_PREREQ_GETDOMAINNAME
89   fi
90 ])
91
92 # Prerequisites of lib/getdomainname.c.
93 AC_DEFUN([gl_PREREQ_GETDOMAINNAME], [
94   if test $ac_cv_func_getdomainname = yes; then
95     AC_DEFINE([HAVE_GETDOMAINNAME], [1],
96       [Define if the getdomainname() function is present and can be used.])
97   fi
98   AC_CHECK_HEADERS([sys/systeminfo.h])
99   AC_CHECK_FUNCS([sysinfo])
100 ])