]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include/c: add get_hostname_max() inline function
authorSami Kerola <kerolasa@iki.fi>
Wed, 17 Oct 2012 19:16:06 +0000 (20:16 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 19 Oct 2012 12:50:27 +0000 (14:50 +0200)
Using sysconf(_SC_HOST_NAME_MAX) does not work everywhere.  At such even
header values for hostname length should be preferred, and if nothing
else works guess the maxium being 64 bytes.

Based-on-code-by: Karel Zak <kzak@redhat.com>
CC: Mike Frysinger <vapier@gentoo.org>
References: http://www.spinics.net/lists/util-linux-ng/msg07050.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
include/c.h

index 64c0138f279108e17fc2bfbc61b6a3f7237e3cb6..e15a994d716876b84be82182466eb972c32a05ce 100644 (file)
@@ -234,6 +234,24 @@ static inline int dirfd(DIR *d)
 # endif
 #endif
 
+/*
+ * MAXHOSTNAMELEN replacement
+ */
+static inline size_t get_hostname_max(void)
+{
+       long len = sysconf(_SC_HOST_NAME_MAX);
+
+       if (0 < len)
+               return len;
+
+#ifdef MAXHOSTNAMELEN
+       return MAXHOSTNAMELEN;
+#elif HOST_NAME_MAX
+       return HOST_NAME_MAX;
+#endif
+       return 64;
+}
+
 /*
  * Constant strings for usage() functions. For more info see
  * Documentation/howto-usage-function.txt and sys-utils/arch.c