[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: HOST_NAME_MAX
From: |
Bruno Haible |
Subject: |
Re: HOST_NAME_MAX |
Date: |
Sun, 2 Aug 2009 12:27:36 +0200 |
User-agent: |
KMail/1.9.9 |
Simon Josefsson wrote on 2009-04-01:
> > The definition can be triggered by the 'gethostname' module. I don't think
> > anyone will need HOST_NAME_MAX without needing the gethostname() function.
>
> That would be fine with me. How about the patch below? This is on top
> of my earlier gethostname patch for mingw.
>
> /Simon
>
> diff --git a/doc/posix-headers/limits.texi b/doc/posix-headers/limits.texi
> index 0b5e431..d404b9c 100644
> --- a/doc/posix-headers/limits.texi
> +++ b/doc/posix-headers/limits.texi
> @@ -11,4 +11,7 @@ Portability problems fixed by Gnulib:
>
> Portability problems not fixed by Gnulib:
> @itemize
> +The @code{HOST_NAME_MAX} symbol is not defined under Windows, use the
> address@hidden gnulib module to get it.
> +
> @end itemize
> diff --git a/m4/gethostname.m4 b/m4/gethostname.m4
> index 620e023..a2b8e60 100644
> --- a/m4/gethostname.m4
> +++ b/m4/gethostname.m4
> @@ -42,7 +42,13 @@ AC_DEFUN([gl_FUNC_GETHOSTNAME],
>
> # Prerequisites of lib/gethostname.c.
> AC_DEFUN([gl_PREREQ_GETHOSTNAME], [
> - if test "$gl_cv_w32_gethostname" != "yes"; then
> + if test "$gl_cv_w32_gethostname" = "yes"; then
> + # <http://msdn.microsoft.com/en-us/library/ms738527.aspx> says:
> + # "if a buffer of 256 bytes is passed in the name parameter and
> + # the namelen parameter is set to 256, the buffer size will always
> + # be adequate."
> + AC_DEFINE([HOST_NAME_MAX], [256], [Define HOST_NAME_MAX on Mingw.])
> + else
> AC_CHECK_FUNCS([uname])
> fi
> ])
> diff --git a/modules/gethostname b/modules/gethostname
> index e21afe6..a50c22b 100644
> --- a/modules/gethostname
> +++ b/modules/gethostname
> @@ -1,5 +1,5 @@
> Description:
> -gethostname() function: Return machine's hostname.
> +Provide HOST_NAME_MAX and gethostname() function: Return machine's hostname.
>
> Files:
> lib/gethostname.c
> diff --git a/tests/test-gethostname.c b/tests/test-gethostname.c
> index ef50953..c1914fd 100644
> --- a/tests/test-gethostname.c
> +++ b/tests/test-gethostname.c
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (C) 2008 Free Software Foundation
> + * Copyright (C) 2008, 2009 Free Software Foundation
> * Written by Simon Josefsson.
> *
> * This program is free software: you can redistribute it and/or modify
> @@ -28,9 +28,15 @@
> int
> main (int argc, char *argv[])
> {
> - char buf[2500];
> + char buf[HOST_NAME_MAX];
> int rc;
>
> + if (strlen (NOHOSTNAME) >= HOST_NAME_MAX)
> + {
> + printf ("HOST_NAME_MAX impossibly small?! %d\n", HOST_NAME_MAX);
> + return 2;
> + }
> +
> strcpy (buf, NOHOSTNAME);
>
> rc = gethostname (buf, sizeof (buf));
>
>
I've applied it with a few tweaks, as follows:
- Document the problem under "problems fixed by Gnulib", not under
"problems not fixed by Gnulib".
- Move the AC_DEFINE out of gl_PREREQ_GETHOSTNAME, since it's the
user who wants HOST_NAME_MAX; the code in lib/gethostname.c does
not need it.
2009-08-02 Simon Josefsson <address@hidden>
Bruno Haible <address@hidden>
Ensure HOST_NAME_MAX as part of the gethostname module.
* m4/gethostname.m4 (gl_FUNC_GETHOSTNAME): On native Windows platforms,
define also HOST_NAME_MAX.
* tests/test-gethostname.c (main): Check also HOST_NAME_MAX.
* doc/posix-headers/limits.texi: Document the mingw problem.
--- doc/posix-headers/limits.texi.orig 2009-08-02 12:23:35.000000000 +0200
+++ doc/posix-headers/limits.texi 2009-08-02 12:19:39.000000000 +0200
@@ -3,10 +3,12 @@
POSIX specification: @url{http://www.opengroup.org/susv3xbd/limits.h.html}
-Gnulib module: ---
+Gnulib module: gethostname
Portability problems fixed by Gnulib:
@itemize
+The @code{HOST_NAME_MAX} macro is not defined on some platforms:
+mingw.
@end itemize
Portability problems not fixed by Gnulib:
--- m4/gethostname.m4.orig 2009-08-02 12:23:35.000000000 +0200
+++ m4/gethostname.m4 2009-08-02 12:23:30.000000000 +0200
@@ -1,9 +1,12 @@
-# gethostname.m4 serial 6
+# gethostname.m4 serial 7
dnl Copyright (C) 2002, 2008, 2009 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.
+# Ensure
+# - the gethostname() function,
+# - the HOST_NAME_MAX macro in <limits.h>.
AC_DEFUN([gl_FUNC_GETHOSTNAME],
[
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
@@ -38,6 +41,16 @@
HAVE_GETHOSTNAME=0
gl_PREREQ_GETHOSTNAME
fi
+
+ dnl Also provide HOST_NAME_MAX when <limits.h> lacks it.
+ if test "$gl_cv_w32_gethostname" = "yes"; then
+ # <http://msdn.microsoft.com/en-us/library/ms738527.aspx> says:
+ # "if a buffer of 256 bytes is passed in the name parameter and
+ # the namelen parameter is set to 256, the buffer size will always
+ # be adequate."
+ AC_DEFINE([HOST_NAME_MAX], [256],
+ [Define HOST_NAME_MAX when <limits.h> does not define it.])
+ fi
])
# Prerequisites of lib/gethostname.c.
--- tests/test-gethostname.c.orig 2009-08-02 12:23:35.000000000 +0200
+++ tests/test-gethostname.c 2009-08-02 12:13:57.000000000 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 Free Software Foundation
+ * Copyright (C) 2008, 2009 Free Software Foundation
* Written by Simon Josefsson.
*
* This program is free software: you can redistribute it and/or modify
@@ -28,9 +28,15 @@
int
main (int argc, char *argv[])
{
- char buf[2500];
+ char buf[HOST_NAME_MAX];
int rc;
+ if (strlen (NOHOSTNAME) >= HOST_NAME_MAX)
+ {
+ printf ("HOST_NAME_MAX impossibly small?! %d\n", HOST_NAME_MAX);
+ return 2;
+ }
+
strcpy (buf, NOHOSTNAME);
rc = gethostname (buf, sizeof (buf));
- Re: HOST_NAME_MAX,
Bruno Haible <=
- Re: HOST_NAME_MAX, Bruno Haible, 2009/08/02
- Re: HOST_NAME_MAX, Tom G. Christensen, 2009/08/06
- Re: HOST_NAME_MAX, Simon Josefsson, 2009/08/06
- Re: HOST_NAME_MAX, Bruno Haible, 2009/08/08
- Re: HOST_NAME_MAX, Simon Josefsson, 2009/08/10
- Re: HOST_NAME_MAX, Bruno Haible, 2009/08/10
- Re: HOST_NAME_MAX, Simon Josefsson, 2009/08/10
- Re: HOST_NAME_MAX, Bruno Haible, 2009/08/10
- Re: HOST_NAME_MAX, Simon Josefsson, 2009/08/11
Re: HOST_NAME_MAX, Simon Josefsson, 2009/08/03