Commit:3ebee4724b965ab973a5ba9632b02deacb07c55d (browse)
Parent:ad2e16560f3fb00f1378ab48c2bb952a9b0af408
Author:kvik <kvik@a-b.xyz>
Date:Tue Feb 4 01:41:58 CET 2020
Message:
Store $%dot in the env(3) in a proper rc(1) list format

sam/shell.c => sam/shell.c
@@ -13,21 +13,29 @@
 static void
 updateenv(File *f)
 {
-	char buf[64], *p;
+	int n, fd;
+	char buf[64], *p, *e;
 	
 	if(f == nil){
 		putenv("%", "");
 		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