summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2008-10-21 13:13:09 +0200
committerBruno Haible <bruno@clisp.org>2008-10-21 13:13:09 +0200
commit655b30edb69df6cb28a431f2b340d0683b0b1f93 (patch)
tree204ec7272b952aaa48a9f79ed3c3f3fd0b2148a6
parent262be897058d3be7ccf3602b861ee5f267d2b361 (diff)
downloadgnulib-655b30edb69df6cb28a431f2b340d0683b0b1f93.tar.gz
Add gethostname() declaration to <unistd.h>.
-rw-r--r--ChangeLog16
-rw-r--r--lib/gethostname.c3
-rw-r--r--lib/unistd.in.h20
-rw-r--r--m4/gethostname.m46
-rw-r--r--m4/unistd_h.m44
-rw-r--r--modules/gethostname3
-rw-r--r--modules/unistd2
-rw-r--r--tests/test-gethostname.c3
8 files changed, 53 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 29976d1078..1b7bbfaf54 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2008-10-21 Bruno Haible <bruno@clisp.org>
+ Add gethostname() declaration to <unistd.h>.
+ * lib/unistd.in.h (gethostname): New declaration.
+ * lib/gethostname.c: Include <unistd.h>.
+ * m4/gethostname.m4 (gl_FUNC_GETHOSTNAME): Require
+ gl_UNISTD_H_DEFAULTS. Set HAVE_GETHOSTNAME.
+ * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_GETHOSTNAME
+ and HAVE_GETHOSTNAME.
+ * modules/gethostname (Depends-on): Add unistd.
+ (configure.ac): Invoke gl_UNISTD_MODULE_INDICATOR.
+ (Include): Specify <unistd.h>.
+ * modules/unistd (Makefile.am): Substitute GNULIB_GETHOSTNAME and
+ HAVE_GETHOSTNAME.
+ * tests/test-gethostname.c: Include <unistd.h> first.
+
+2008-10-21 Bruno Haible <bruno@clisp.org>
+
* modules/poll-tests (Depends-on): Add sys_ioctl, ioctl.
* modules/select-tests (Depends-on): Likewise.
Reported by Simon Josefsson.
diff --git a/lib/gethostname.c b/lib/gethostname.c
index 169dd4ef3b..acff351d87 100644
--- a/lib/gethostname.c
+++ b/lib/gethostname.c
@@ -19,6 +19,9 @@
#include <config.h>
+/* Specification. */
+#include <unistd.h>
+
#ifdef HAVE_UNAME
# include <sys/utsname.h>
#endif
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index 3700958966..bfa3d49cb2 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -272,6 +272,26 @@ extern int getdtablesize (void);
#endif
+#if @GNULIB_GETHOSTNAME@
+/* Return the standard host name of the machine.
+ WARNING! The host name may or may not be fully qualified.
+
+ Put up to LEN bytes of the host name into NAME.
+ Null terminate it if the name is shorter than LEN.
+ If the host name is longer than LEN, set errno = EINVAL and return -1.
+ Return 0 if successful, otherwise set errno and return -1. */
+# if !@HAVE_GETHOSTNAME@
+extern int gethostname(char *name, size_t len);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef gethostname
+# define gethostname(n,l) \
+ (GL_LINK_WARNING ("gethostname is unportable - " \
+ "use gnulib module gethostname for portability"), \
+ gethostname (n, l))
+#endif
+
+
#if @GNULIB_GETLOGIN_R@
/* Copies the user's login name to NAME.
The array pointed to by NAME has room for SIZE bytes.
diff --git a/m4/gethostname.m4 b/m4/gethostname.m4
index 1e9749d39e..b8c4e2a75a 100644
--- a/m4/gethostname.m4
+++ b/m4/gethostname.m4
@@ -1,13 +1,15 @@
-# gethostname.m4 serial 2
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# gethostname.m4 serial 3
+dnl Copyright (C) 2002, 2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_GETHOSTNAME],
[
+ AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
AC_REPLACE_FUNCS(gethostname)
if test $ac_cv_func_gethostname = no; then
+ HAVE_GETHOSTNAME=0
gl_PREREQ_GETHOSTNAME
fi
])
diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4
index 7a3798be9f..5685273656 100644
--- a/m4/unistd_h.m4
+++ b/m4/unistd_h.m4
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 15
+# unistd_h.m4 serial 16
dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -43,6 +43,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD])
GNULIB_GETDOMAINNAME=0; AC_SUBST([GNULIB_GETDOMAINNAME])
GNULIB_GETDTABLESIZE=0; AC_SUBST([GNULIB_GETDTABLESIZE])
+ GNULIB_GETHOSTNAME=0; AC_SUBST([GNULIB_GETHOSTNAME])
GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R])
GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE])
GNULIB_GETUSERSHELL=0; AC_SUBST([GNULIB_GETUSERSHELL])
@@ -59,6 +60,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE])
HAVE_GETDOMAINNAME=1; AC_SUBST([HAVE_GETDOMAINNAME])
HAVE_GETDTABLESIZE=1; AC_SUBST([HAVE_GETDTABLESIZE])
+ HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME])
HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE])
HAVE_GETUSERSHELL=1; AC_SUBST([HAVE_GETUSERSHELL])
HAVE_READLINK=1; AC_SUBST([HAVE_READLINK])
diff --git a/modules/gethostname b/modules/gethostname
index 7c1380764d..2fffbb1b2b 100644
--- a/modules/gethostname
+++ b/modules/gethostname
@@ -6,13 +6,16 @@ lib/gethostname.c
m4/gethostname.m4
Depends-on:
+unistd
configure.ac:
gl_FUNC_GETHOSTNAME
+gl_UNISTD_MODULE_INDICATOR([gethostname])
Makefile.am:
Include:
+<unistd.h>
License:
LGPL
diff --git a/modules/unistd b/modules/unistd
index 2f1c0aab93..225abf9879 100644
--- a/modules/unistd
+++ b/modules/unistd
@@ -35,6 +35,7 @@ unistd.h: unistd.in.h
-e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
-e 's|@''GNULIB_GETDOMAINNAME''@|$(GNULIB_GETDOMAINNAME)|g' \
-e 's|@''GNULIB_GETDTABLESIZE''@|$(GNULIB_GETDTABLESIZE)|g' \
+ -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \
-e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
-e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \
-e 's|@''GNULIB_GETUSERSHELL''@|$(GNULIB_GETUSERSHELL)|g' \
@@ -50,6 +51,7 @@ unistd.h: unistd.in.h
-e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
-e 's|@''HAVE_GETDOMAINNAME''@|$(HAVE_GETDOMAINNAME)|g' \
-e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \
+ -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \
-e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
-e 's|@''HAVE_GETUSERSHELL''@|$(HAVE_GETUSERSHELL)|g' \
-e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \
diff --git a/tests/test-gethostname.c b/tests/test-gethostname.c
index 01f9369934..ef509530ba 100644
--- a/tests/test-gethostname.c
+++ b/tests/test-gethostname.c
@@ -17,10 +17,11 @@
#include <config.h>
+#include <unistd.h>
+
#include <stdio.h>
#include <string.h>
#include <errno.h>
-#include <unistd.h>
#define NOHOSTNAME "magic-gnulib-test-string"