maint: update copyright
[gnulib.git] / m4 / getdomainname.m4
1 # getdomainname.m4 serial 10
2 dnl Copyright (C) 2002-2003, 2008-2014 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 it 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
32               #ifdef __cplusplus
33               "C"
34               #endif
35               int getdomainname (char *, size_t);
36             ]],
37             [[getdomainname(NULL, 0);]])],
38          [gl_cv_func_getdomainname_in_libnsl=yes])
39        LIBS="$gl_save_LIBS"
40       ])
41   ])
42
43   dnl What about the declaration?
44   dnl - It's  int getdomainname(char *, size_t)  on glibc, NetBSD, OpenBSD.
45   dnl - It's  int getdomainname(char *, int)  on Mac OS X, FreeBSD, AIX, IRIX,
46   dnl   OSF/1.
47   AC_CHECK_DECLS([getdomainname], , ,
48     [[#include <sys/types.h>
49       #ifdef HAVE_SYS_SOCKET_H
50       #include <sys/socket.h>
51       #endif
52       #ifdef HAVE_NETDB_H
53       #include <netdb.h>
54       #endif
55       #include <unistd.h>
56     ]])
57   AC_CACHE_CHECK([for getdomainname's second argument type],
58     [gl_cv_decl_getdomainname_argtype2],
59     [if test $ac_cv_have_decl_getdomainname; then
60        AC_COMPILE_IFELSE(
61          [AC_LANG_PROGRAM(
62             [[#include <sys/types.h>
63               #ifdef HAVE_SYS_SOCKET_H
64               #include <sys/socket.h>
65               #endif
66               #ifdef HAVE_NETDB_H
67               #include <netdb.h>
68               #endif
69               #include <unistd.h>
70               extern
71               #ifdef __cplusplus
72               "C"
73               #endif
74               int getdomainname (char *, int);
75             ]],
76             [[]])],
77          [gl_cv_decl_getdomainname_argtype2='int'],
78          [gl_cv_decl_getdomainname_argtype2='size_t'])
79      else
80        gl_cv_decl_getdomainname_argtype2='int'
81      fi
82     ])
83
84   if test $ac_cv_have_decl_getdomainname = no; then
85     HAVE_DECL_GETDOMAINNAME=0
86   fi
87
88   if { test $ac_cv_func_getdomainname = yes \
89        && test $gl_cv_decl_getdomainname_argtype2 != size_t; \
90      } \
91      || test "$gl_cv_func_getdomainname_in_libnsl" = yes; then
92     REPLACE_GETDOMAINNAME=1
93   fi
94 ])
95
96 # Prerequisites of lib/getdomainname.c.
97 AC_DEFUN([gl_PREREQ_GETDOMAINNAME], [
98   if test $ac_cv_func_getdomainname = yes; then
99     AC_DEFINE([HAVE_GETDOMAINNAME], [1],
100       [Define if the getdomainname() function is present and can be used.])
101   fi
102   AC_CHECK_HEADERS([sys/systeminfo.h])
103   AC_CHECK_FUNCS([sysinfo])
104 ])