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.
7 AC_DEFUN([gl_FUNC_GETDOMAINNAME],
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
13 dnl Persuade glibc <unistd.h> to declare getdomainname().
14 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
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
31 extern int getdomainname (char *, size_t);
33 [[getdomainname(NULL, 0);]])],
34 [gl_cv_func_getdomainname_in_libnsl=yes])
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,
43 AC_CHECK_DECLS([getdomainname], , ,
44 [#include <sys/types.h>
45 #ifdef HAVE_SYS_SOCKET_H
46 #include <sys/socket.h>
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
58 [[#include <sys/types.h>
59 #ifdef HAVE_SYS_SOCKET_H
60 #include <sys/socket.h>
66 extern int getdomainname (char *, int);]],
68 [gl_cv_decl_getdomainname_argtype2='int'],
69 [gl_cv_decl_getdomainname_argtype2='size_t'])
71 gl_cv_decl_getdomainname_argtype2='int'
75 if test $ac_cv_have_decl_getdomainname = no; then
76 HAVE_DECL_GETDOMAINNAME=0
79 if { test $ac_cv_func_getdomainname = yes \
80 && test $gl_cv_decl_getdomainname_argtype2 != size_t; \
82 || test "$gl_cv_func_getdomainname_in_libnsl" = yes; then
83 REPLACE_GETDOMAINNAME=1
86 if test $HAVE_DECL_GETDOMAINNAME = 0 || test $REPLACE_GETDOMAINNAME = 1; then
87 AC_LIBOBJ([getdomainname])
88 gl_PREREQ_GETDOMAINNAME
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.])
98 AC_CHECK_HEADERS([sys/systeminfo.h])
99 AC_CHECK_FUNCS([sysinfo])