9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] [patch] archfs replace hand rolled emalloc wit emalloc9p
@ 2023-01-13 17:23 Arne Meyer
  0 siblings, 0 replies; only message in thread
From: Arne Meyer @ 2023-01-13 17:23 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 87 bytes --]

Hello,

lib9p already has what we need. No need to reinvent the wheel.

Greetings,
Arne

[-- Attachment #2: archfs.patch --]
[-- Type: application/octet-stream, Size: 1011 bytes --]

diff c10be29c773737c4159b613f4f6c3b5a90d732f6 uncommitted
--- a/sys/src/cmd/archfs.c
+++ b/sys/src/cmd/archfs.c
@@ -26,28 +26,7 @@
 	vlong length;
 };
 
-static void*
-emalloc(long sz)
-{
-	void *v;
-
-	v = malloc(sz);
-	if(v == nil)
-		sysfatal("malloc %lud fails", sz);
-	memset(v, 0, sz);
-	return v;
-}
-
 static char*
-estrdup(char *s)
-{
-	s = strdup(s);
-	if(s == nil)
-		sysfatal("strdup (%.10s) fails", s);
-	return s;
-}
-
-static char*
 Bgetline(Biobuf *b)
 {
 	char *p;
@@ -76,11 +55,11 @@
 		return nil;
 	}
 
-	a = emalloc(sizeof(*a));
-	a->name = estrdup(f[0]);
+	a = emalloc9p(sizeof(*a));
+	a->name = estrdup9p(f[0]);
 	a->mode = strtoul(f[1], 0, 8);
-	a->uid = estrdup(f[2]);
-	a->gid = estrdup(f[3]);
+	a->uid = estrdup9p(f[2]);
+	a->gid = estrdup9p(f[3]);
 	a->mtime = strtoll(f[4], 0, 10);
 	a->length = strtoll(f[5], 0, 10);
 	return a;
@@ -94,7 +73,7 @@
 
 	if(nabuf == 0) {
 		nabuf = 256;
-		abuf = emalloc(sizeof(Arch)*nabuf);
+		abuf = emalloc9p(sizeof(Arch)*nabuf);
 	}
 
 	nabuf--;

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

only message in thread, other threads:[~2023-01-13 17:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-13 17:23 [9front] [patch] archfs replace hand rolled emalloc wit emalloc9p Arne Meyer

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).