From 1bfd27e8f646230d7d17d9776c9c58a086fbc42e Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 31 Jul 2025 19:14:01 +0200 Subject: [PATCH] xfree86: parser: use xhostname() Simplify DoSubstitution() by using xhostname(). Neither need to care about OS specifics here, nor take care of zero-terminating the hostname string - xhostname() is already doing this. Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xfree86/parser/scan.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c index 822317f7f..5c44ae59b 100644 --- a/hw/xfree86/parser/scan.c +++ b/hw/xfree86/parser/scan.c @@ -66,11 +66,10 @@ #include #include #include -#include "xf86Parser_priv.h" -#if !defined(MAXHOSTNAMELEN) -#define MAXHOSTNAMELEN 32 -#endif /* !MAXHOSTNAMELEN */ +#include "os/xhostname.h" + +#include "xf86Parser_priv.h" /* For PATH_MAX */ #include "misc.h" @@ -625,15 +624,9 @@ DoSubstitution(const char *template, const char *cmdline, const char *projroot, break; case 'H': if (!hostname) { - if ((hostname = calloc(1, MAXHOSTNAMELEN + 1))) { - if (gethostname(hostname, MAXHOSTNAMELEN) == 0) { - hostname[MAXHOSTNAMELEN] = '\0'; - } - else { - free(hostname); - hostname = NULL; - } - } + struct xhostname hn; + if (xhostname(&hn)) + hostname = strdup(hn.name); } if (hostname) APPEND_STR(hostname);