|
Message-Id: <20200803205529.2232-1-ericonr@disroot.org> Date: Mon, 3 Aug 2020 17:55:29 -0300 From: Érico Rolim <ericonr@...root.org> To: musl@...ts.openwall.com Cc: Érico Rolim <erico.erc@...il.com> Subject: [PATCH] extend gethostid beyond a stub From: Érico Rolim <erico.erc@...il.com> Implement part of the glibc behavior, where the 32-bit identifier stored in /etc/hostid, if the file exists, is returned. If this file doesn't contain at least 32 bits or can't be opened for some reason, return 0. --- src/misc/gethostid.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/misc/gethostid.c b/src/misc/gethostid.c index 25bb35db..e2e98b99 100644 --- a/src/misc/gethostid.c +++ b/src/misc/gethostid.c @@ -1,6 +1,19 @@ #include <unistd.h> +#include <stdio.h> long gethostid() { - return 0; + FILE *f; + unsigned char hostid[4]; + long rv = 0; + + f = fopen("/etc/hostid", "reb"); + if (f) { + if (fread(hostid, 1, 4, f) == 4) { + rv = (hostid[3] << 24) | (hostid[2] << 16) | (hostid[1] << 8) | hostid[0]; + } + fclose(f); + } + + return rv; } -- 2.28.0
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.