From: Simon Schubert <2@0x2c.org> Date: Thu, 28 Oct 2010 22:10:30 +0000 (+0200) Subject: use HOST_NAME_MAX instead of MAXHOSTNAMELEN X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d6240370fb7dfa09ddd6e3512411cb1389c64786;p=people%2Fms%2Fdma.git use HOST_NAME_MAX instead of MAXHOSTNAMELEN HOST_NAME_MAX is sanctioned by POSIX. drop 37-gnu-hurd.patch: already applied / other fix here --- diff --git a/debian/patches/37-gnu-hurd.patch b/debian/patches/37-gnu-hurd.patch deleted file mode 100644 index 2a9c0d9..0000000 --- a/debian/patches/37-gnu-hurd.patch +++ /dev/null @@ -1,42 +0,0 @@ -Description: Further fixes to the build on the GNU Hurd - - include for LOCK_EX - - define MAXHOSTNAMELEN if absent -Forwarded: no -Author: Peter Pentchev -Last-Update: 2010-10-16 - ---- a/spool.c -+++ b/spool.c -@@ -32,6 +32,7 @@ - * SUCH DAMAGE. - */ - -+#include - #include - - #include ---- a/util.c -+++ b/util.c -@@ -33,6 +33,7 @@ - */ - - #include -+#include - #include - #include - #include -@@ -43,6 +44,14 @@ - - #include "dma.h" - -+/** -+ * A quick'n'dirty hack to get dma to build on the GNU Hurd. -+ * A real fix would dynamically allocate the hostname array. -+ */ -+#ifndef MAXHOSTNAMELEN -+#define MAXHOSTNAMELEN 1024 -+#endif -+ - const char * - hostname(void) - { diff --git a/util.c b/util.c index 6381aaf..83002f4 100644 --- a/util.c +++ b/util.c @@ -51,7 +51,7 @@ const char * hostname(void) { - static char name[MAXHOSTNAMELEN+1]; + static char name[HOST_NAME_MAX+1]; static int initialized = 0; if (initialized) @@ -95,6 +95,11 @@ hostname(void) local: if (gethostname(name, sizeof(name)) != 0) strcpy(name, "(unknown hostname)"); + /* + * gethostname() is allowed to truncate name without NUL-termination + * and at the same time not return an error. + */ + name[sizeof(name) - 1] = 0; initialized = 1; return (name); }