summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-06-23 22:43:53 -0700
committerOri Bernstein <ori@eigenstate.org>2018-06-23 23:12:19 -0700
commitfde9deac883c3f2ae6ffb7d05b4f5e404f5c2249 (patch)
tree952dcd801a7e807486ecdc43c0b9e1c2a7a4ae0c
parent1779c6b7aedf6bb7665b8f650f37958340f3177c (diff)
downloadmc-fde9deac883c3f2ae6ffb7d05b4f5e404f5c2249.tar.gz
bfmt may alloc.
Let's do our own that's guaranteed never to alloc. This solves the same threading issue mentioned earlier.
-rw-r--r--lib/std/execvp.myr19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/std/execvp.myr b/lib/std/execvp.myr
index c24ea47..8c1bffe 100644
--- 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 @@ const execvp = {cmd, args
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 @@ const execvpe = {cmd, args, env
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 @@ const nextpath = {p, start
-> (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]
+}