shithub: ham

Download patch

ref: 3ebee4724b965ab973a5ba9632b02deacb07c55d
parent: ad2e16560f3fb00f1378ab48c2bb952a9b0af408
author: kvik <kvik@a-b.xyz>
date: Mon Feb 3 19:41:58 EST 2020

Store $%dot in the env(3) in a proper rc(1) list format

--- a/sam/shell.c
+++ b/sam/shell.c
@@ -13,7 +13,8 @@
 static void
 updateenv(File *f)
 {
-	char buf[64], *p;
+	int n, fd;
+	char buf[64], *p, *e;
 	
 	if(f == nil){
 		putenv("%", "");
@@ -20,14 +21,21 @@
 		putenv("%dot", "");
 		return;
 	}
+
 	p = Strtoc(&f->name);
 	putenv("%", p);
 	free(p);
-	snprint(buf, sizeof buf, "%lud %lud %lud",
-		1+nlcount(f, 0, f->dot.r.p1),
-		f->dot.r.p1,
-		f->dot.r.p2);
-	putenv("%dot", buf);
+	
+	p = buf;
+	e = buf+sizeof(buf);
+	p = seprint(p, e, "%lud", 1+nlcount(f, 0, f->dot.r.p1));
+	p = seprint(p+1, e, "%lud", f->dot.r.p1);
+	p = seprint(p+1, e, "%lud", f->dot.r.p2);
+	n = p - buf;
+	if((fd = create("/env/%dot", OWRITE, 0666)) < 0)
+		fprint(2, "updateenv create: %r\n");
+	if(write(fd, buf, n) != n)
+		fprint(2, "updateenv write: %r\n");
 }
 
 int