From 81532829233431b12f325df3f09a5e86460117b1 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Fri, 14 Jan 2022 00:32:55 +0100 Subject: [PATCH] LibCore: Remove usage of a hardcoded constant in gethostname() --- Userland/Libraries/LibCore/System.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index ac83adbda2..f29fb758ca 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,14 @@ namespace Core::System { +#ifndef HOST_NAME_MAX +# ifdef __APPLE__ +# define HOST_NAME_MAX 255 +# else +# define HOST_NAME_MAX 64 +# endif +#endif + #ifdef __serenity__ ErrorOr beep() @@ -336,7 +345,7 @@ ErrorOr ptsname(int fd) ErrorOr gethostname() { - char hostname[256]; + char hostname[HOST_NAME_MAX]; int rc = ::gethostname(hostname, sizeof(hostname)); if (rc < 0) return Error::from_syscall("gethostname"sv, -errno);