From: Sami Kerola Date: Wed, 17 Oct 2012 19:16:06 +0000 (+0100) Subject: include/c: add get_hostname_max() inline function X-Git-Tag: v2.23-rc1~602 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1ee4dff7246949cbebef884d84ccdc127450bee0;p=thirdparty%2Futil-linux.git include/c: add get_hostname_max() inline function 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 CC: Mike Frysinger References: http://www.spinics.net/lists/util-linux-ng/msg07050.html Signed-off-by: Sami Kerola Signed-off-by: Karel Zak --- diff --git a/include/c.h b/include/c.h index 64c0138f27..e15a994d71 100644 --- a/include/c.h +++ b/include/c.h @@ -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