diff options
author | Sami Kerola | 2012-10-17 21:16:06 +0200 |
---|---|---|
committer | Karel Zak | 2012-10-19 14:50:27 +0200 |
commit | 1ee4dff7246949cbebef884d84ccdc127450bee0 (patch) | |
tree | 1af3a454706d0179a407f1813734a8b6ec2b1c57 /include/c.h | |
parent | fdisk: gpt: use swap_efi_guid for new partitions (diff) | |
download | kernel-qcow2-util-linux-1ee4dff7246949cbebef884d84ccdc127450bee0.tar.gz kernel-qcow2-util-linux-1ee4dff7246949cbebef884d84ccdc127450bee0.tar.xz kernel-qcow2-util-linux-1ee4dff7246949cbebef884d84ccdc127450bee0.zip |
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 <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>
Diffstat (limited to 'include/c.h')
-rw-r--r-- | include/c.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/c.h b/include/c.h index 64c0138f2..e15a994d7 100644 --- a/include/c.h +++ b/include/c.h @@ -235,6 +235,24 @@ static inline int dirfd(DIR *d) #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 */ |