From 14bcae1344091400e419fd9896024a290792ee41 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 10 Oct 2023 10:48:38 +0200 Subject: Merging upstream version 4.2+20230901. Signed-off-by: Daniel Baumann --- lib.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib.c') diff --git a/lib.c b/lib.c index fe5c8d2..8a4b48e 100644 --- a/lib.c +++ b/lib.c @@ -585,3 +585,22 @@ int parse_num(int *dest, const char *num) *dest = temp; return 0; } + +/** + * s_gethostname() - secure get hostname. Assure null-terminated string. + * + * @buf: buffer for hostname. + * @buf_len: buffer length. + * + * Return: gethostname() result. + */ +int s_gethostname(char *buf, int buf_len) +{ + assert(buf); + + int ret = gethostname(buf, buf_len); + + buf[buf_len - 1] = 0; + + return ret; +} -- cgit v1.2.3