From 2384791793f25d72e7e694b0776f86d3a7b1fa0c Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Wed, 12 Feb 2025 02:53:13 +0200 Subject: [PATCH] userspace/libc: add stub gethostname function Signed-off-by: EnderIce2 --- Userspace/libc/include/unistd.h | 1 + Userspace/libc/src/std/unistd.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Userspace/libc/include/unistd.h b/Userspace/libc/include/unistd.h index 0be84937..1106d1e5 100644 --- a/Userspace/libc/include/unistd.h +++ b/Userspace/libc/include/unistd.h @@ -94,6 +94,7 @@ extern "C" gid_t getgid(void); int getgroups(int, gid_t[]); long gethostid(void); + int gethostname(char *name, size_t namelen); char *getlogin(void); int getlogin_r(char *, size_t); int getopt(int, char *const[], const char *); diff --git a/Userspace/libc/src/std/unistd.c b/Userspace/libc/src/std/unistd.c index 5426990d..d240e1d7 100644 --- a/Userspace/libc/src/std/unistd.c +++ b/Userspace/libc/src/std/unistd.c @@ -179,6 +179,25 @@ export uid_t geteuid(void); export gid_t getgid(void); export int getgroups(int, gid_t[]); export long gethostid(void); + +export int gethostname(char *name, size_t namelen) +{ + if (namelen == 0) + { + errno = EINVAL; + return -1; + } + + strncpy(name, "localhost", namelen); + if (namelen < strlen("localhost") + 1) + { + errno = ENAMETOOLONG; + return -1; + } + + return 0; +} + export char *getlogin(void); export int getlogin_r(char *, size_t); export int getopt(int, char *const[], const char *);