mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH v3] extend gethostid beyond a stub
@ 2020-08-04 22:42 Érico Rolim
  0 siblings, 0 replies; only message in thread
From: Érico Rolim @ 2020-08-04 22:42 UTC (permalink / raw)
  To: musl; +Cc: Érico Rolim

From: Érico Rolim <erico.erc@gmail.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.
---

Andre McCurdy, thanks for the review.
 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..ac84b82d 100644
--- a/src/misc/gethostid.c
+++ b/src/misc/gethostid.c
@@ -1,6 +1,19 @@
 #include <unistd.h>
+#include <stdio.h>
+#include <stdint.h>
 
 long gethostid()
 {
-	return 0;
+	FILE *f;
+	int32_t rv = 0;
+
+	f = fopen("/etc/hostid", "reb");
+	if (f) {
+		if (fread(&rv, 4, 1, f) == 0) {
+			rv = 0;
+		}
+		fclose(f);
+	}
+
+	return rv;
 }
-- 
2.28.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-04 22:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-04 22:42 [musl] [PATCH v3] extend gethostid beyond a stub Érico Rolim

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).