shithub: mc

Download patch

ref: fde9deac883c3f2ae6ffb7d05b4f5e404f5c2249
parent: 1779c6b7aedf6bb7665b8f650f37958340f3177c
author: Ori Bernstein <[email protected]>
date: Sat Jun 23 18:43:53 EDT 2018

bfmt may alloc.

	Let's do our own that's guaranteed never to alloc.
	This solves the same threading issue mentioned earlier.

--- a/lib/std/execvp.myr
+++ b/lib/std/execvp.myr
@@ -1,10 +1,10 @@
 use "alloc"
 use "env"
 use "errno"
-use "fmt"
 use "option"
 use "strfind"
 use "syswrap"
+use "slcp"
 
 pkg std = 
 	const execvp	: (cmd : byte[:], args : byte[:][:] -> errno)
@@ -24,7 +24,7 @@
 		paths = std.getenvv("PATH", "/usr/local/bin:/bin:/usr/bin")
 		while j < paths.len
 			(i, j) = nextpath(paths, j)
-			binpath = bfmt(buf[:], "{}/{}", paths[i:j], cmd)
+			binpath = mkpath(buf[:], paths[i:j], cmd)
 			execv(binpath, args)
 		;;
 	;;
@@ -44,7 +44,7 @@
 		paths = std.getenvv("PATH", "/usr/local/bin:/bin:/usr/bin")
 		while j < paths.len
 			(i, j) = nextpath(paths, j)
-			binpath = bfmt(buf[:], "{}/{}", paths[i:j], cmd)
+			binpath = mkpath(buf[:], paths[i:j], cmd)
 			execve(binpath, args, env)
 		;;
 	;;
@@ -65,3 +65,16 @@
 	-> (i, j)
 }
 
+const mkpath = {buf, path, bin
+	var p, b
+
+	p = path.len
+	b = bin.len
+	if buf.len < p + b + 1
+		-> ""
+	;;
+	std.slcp(buf[:p], path)
+	std.slcp(buf[p:p + 1], "/")
+	std.slcp(buf[p + 1:p + b + 1], bin)
+	-> buf[:p + b + 1]
+}