1 # gethostname.m4 serial 6
2 dnl Copyright (C) 2002, 2008, 2009 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_GETHOSTNAME],
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 gl_PREREQ_SYS_H_WINSOCK2
12 dnl Where is gethostname() defined?
13 dnl - On native Windows, it is in ws2_32.dll.
14 dnl - Otherwise is is in libc.
16 AC_CHECK_FUNCS([gethostname], , [
17 AC_CACHE_CHECK([for gethostname in winsock2.h and -lws2_32],
18 [gl_cv_w32_gethostname],
19 [gl_cv_w32_gethostname=no
23 #ifdef HAVE_WINSOCK2_H
27 ], [gethostname(NULL, 0);], [gl_cv_w32_gethostname=yes])
30 if test "$gl_cv_w32_gethostname" = "yes"; then
31 GETHOSTNAME_LIB="-lws2_32"
34 AC_SUBST([GETHOSTNAME_LIB])
36 if test "$ac_cv_func_gethostname" = no; then
37 AC_LIBOBJ([gethostname])
43 # Prerequisites of lib/gethostname.c.
44 AC_DEFUN([gl_PREREQ_GETHOSTNAME], [
45 if test "$gl_cv_w32_gethostname" != "yes"; then
46 AC_CHECK_FUNCS([uname])