ref: f366166b75c22f674c6b8b5129cdf127608acc81
parent: 68dc8fd88d1fc23d6b882531343b38a8e2c7ac99
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Apr 14 13:33:24 EDT 2015
Get a more or less working getcwd under OSX. TODO: It still truncates long paths.
--- a/libstd/cstrconv.myr
+++ b/libstd/cstrconv.myr
@@ -1,6 +1,7 @@
use "types.use"
pkg std =
+ const cstrlen : (buf : byte[:] -> size)
const cstrconv : (buf : byte[:] -> byte[:])
const cstrconvp : (p : byte# -> byte[:])
;;
@@ -25,4 +26,15 @@
i++
;;
-> p[:i]
+}
+
+const cstrlen = {buf
+ var i
+
+ for i = 0; i < buf.len; i++
+ if buf[i] == 0
+ break
+ ;;
+ ;;
+ -> i
}
--- a/libstd/getcwd.myr
+++ b/libstd/getcwd.myr
@@ -17,7 +17,7 @@
n = bgetcwd(buf)
if n >= 0
/* n is the length of the nul terminated c string */
- -> buf[:n-1]
+ -> buf[:n]
elif n != Erange
std.slfree(buf)
-> ""
--- a/libstd/syswrap-ss+posixy-linux.myr
+++ b/libstd/syswrap-ss+posixy-linux.myr
@@ -6,4 +6,16 @@
;;
const exit = {status; sys.exit_group(status)}
-const bgetcwd = {buf; -> sys.getcwd(buf) castto(errno)}
+const bgetcwd = {buf;
+ var err
+ err = sys.getcwd(buf) castto(errno)
+ /*
+ if we got a length back, it includes
+ the nul byte. chop that off.
+ */
+ if err > 0
+ -> err - 1
+ else
+ -> err
+ ;;
+}
--- a/libstd/syswrap-ss+posixy-osx.myr
+++ b/libstd/syswrap-ss+posixy-osx.myr
@@ -1,5 +1,8 @@
use sys
use "errno.use"
+use "cstrconv.use"
+use "slcp.use"
+use "die.use"
pkg std =
const exit : (status:int -> void)
@@ -9,7 +12,7 @@
const exit = {status; sys.exit(status)}
const bgetcwd = {buf
var path : byte[sys.Maxpathlen]
- var fd
+ var fd, len, err
fd = sys.open(".", sys.Ordonly)
if fd < 0
@@ -19,5 +22,14 @@
FIXME: if the path is longer than sys.Pathmax, we should fall back to
the ugly method of finding the path.
*/
- -> sys.fcntl(fd, sys.Fgetpath, path[:] castto(byte#)) castto(errno)
+ err = sys.fcntl(fd, sys.Fgetpath, path[:] castto(byte#)) castto(errno)
+ if err < 0
+ -> err
+ ;;
+ len = cstrlen(path[:])
+ if len >= buf.len
+ -> Erange
+ ;;
+ slcp(buf[:len], path[:len])
+ -> len castto(errno)
}
--- a/mbld/main.myr
+++ b/mbld/main.myr
@@ -18,10 +18,7 @@
var bintarg
var optctx
- /*
optctx = std.optinit("hb:l:s:Sr:I:C:A:M:L:R:d", args)
- */
- optctx = std.optinit("", args)
bld.initopts()
while !std.optdone(optctx)
match std.optnext(optctx)
@@ -102,6 +99,9 @@
b = std.zalloc()
b.targs = std.mkht(std.strhash, std.streq)
b.gensrc = std.mkht(std.strhash, std.streq)
+ /*
+ b.basedir = std.sldup("/Users/orib/src/myr/mc")
+ */
b.basedir = std.getcwd()
b.curdir = ""
-> b
--- a/mbld/parse.myr
+++ b/mbld/parse.myr
@@ -31,7 +31,6 @@
var p : parser#
var subpath, subbld, ok
- std.put("loading %s in dir '%s'\n", path, dir)
p = mkparser(path, dir, b.basedir)
ok = bld.parse(b, p, "")
for s in p.subdirs
@@ -63,13 +62,11 @@
const freeparser = {p
std.slfree(p.fname)
- /*
std.slfree(p.fdir)
std.slfree(p.basedir)
std.slfree(p.subdirs)
std.slfree(p.data)
std.free(p)
- */
}
const failparse = {p, msg, args : ...
--- a/mbldwrap.sh
+++ b/mbldwrap.sh
@@ -1,5 +1,9 @@
#!/bin/sh
+export MYR_MUSE=../muse/muse
+export MYR_MC=../6/6m
+export MYR_RT=../rt/_myrrt.o
+
# this should be a bourne compatible shell script.
if test -f mbld/mbld; then
./mbld/mbld $@