summaryrefslogtreecommitdiff
path: root/libstd
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-04-13 00:58:08 -0700
committerOri Bernstein <ori@eigenstate.org>2015-04-13 00:58:08 -0700
commit46353c77c6d4203f9ea8da76510fad62da42b2db (patch)
tree33d73c65560e88413228057adb8991c2d7f38b07 /libstd
parent642dae20a73cca3ab40127639361af0f72423be8 (diff)
downloadmc-46353c77c6d4203f9ea8da76510fad62da42b2db.tar.gz
Implement getcwd() on Linux.
This is needed for the newest mbld.
Diffstat (limited to 'libstd')
-rw-r--r--libstd/Makefile1
-rw-r--r--libstd/bldfile13
-rw-r--r--libstd/getcwd.myr30
-rw-r--r--libstd/sys+linux-x64.myr2
-rw-r--r--libstd/syswrap+posixy.myr5
5 files changed, 44 insertions, 7 deletions
diff --git a/libstd/Makefile b/libstd/Makefile
index 9386d20..c5537c5 100644
--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -48,6 +48,7 @@ STDSRC= \
fltbits.myr \
fmt.myr \
fltfmt.myr \
+ getcwd.myr \
hashfuncs.myr \
hasprefix.myr \
hassuffix.myr \
diff --git a/libstd/bldfile b/libstd/bldfile
index e7e98b1..b055493 100644
--- a/libstd/bldfile
+++ b/libstd/bldfile
@@ -36,21 +36,22 @@ lib std {inc=.} =
endian.myr
env+posixy.myr
env+plan9.myr
- errno.myr
+ errno.myr
execvp.myr
extremum.myr
fltbits.myr
fltfmt.myr
fmt.myr
+ getcwd.myr
hashfuncs.myr
hasprefix.myr
hassuffix.myr
htab.myr
- getint.myr
+ getint.myr
intparse.myr
ipparse.myr
mk.myr
- mkpath.myr
+ mkpath.myr
now.myr
option.myr
optparse.myr
@@ -75,9 +76,9 @@ lib std {inc=.} =
strjoin.myr
strsplit.myr
strstrip.myr
- syswrap+plan9.myr
- syswrap-ss+posixy-linux.myr
- syswrap-ss+posixy-osx.myr
+ syswrap+plan9.myr
+ syswrap-ss+posixy-linux.myr
+ syswrap-ss+posixy-osx.myr
syswrap+posixy.myr
swap.myr
try.myr
diff --git a/libstd/getcwd.myr b/libstd/getcwd.myr
new file mode 100644
index 0000000..3992bf6
--- /dev/null
+++ b/libstd/getcwd.myr
@@ -0,0 +1,30 @@
+use "syswrap.use"
+use "errno.use"
+use "alloc.use"
+use "extremum.use"
+use "fmt.use"
+
+pkg std =
+ const getcwd : (-> byte[:])
+;;
+
+const getcwd = {
+ var len, n, buf
+
+ len = 128
+ while true
+ buf = std.slalloc(len)
+ n = bgetcwd(buf)
+ std.put("got %i, buf = %s\n", n, buf[:n])
+ if n >= 0
+ /* n is the length of the nul terminated c string */
+ -> buf[:n-1]
+ elif n != Erange
+ std.slfree(buf)
+ -> ""
+ else
+ len *= 2
+ ;;
+ ;;
+}
+
diff --git a/libstd/sys+linux-x64.myr b/libstd/sys+linux-x64.myr
index 7d87422..2642b65 100644
--- a/libstd/sys+linux-x64.myr
+++ b/libstd/sys+linux-x64.myr
@@ -608,6 +608,7 @@ pkg sys =
generic ioctl : (fd:fd, req : int64, arg:@a# -> int64)
const getdents64 : (fd:fd, buf : byte[:] -> int64)
const chdir : (p : byte[:] -> int64)
+ const getcwd : (buf : byte[:] -> int64)
/* fd stuff */
const pipe : (fds : fd[2]# -> int64)
@@ -726,6 +727,7 @@ const mkdir = {path, mode; -> syscall(Sysmkdir, cstring(path), a(mode)) castto(
generic ioctl = {fd, req, arg; -> syscall(Sysioctl, a(fd), a(req), a(arg)) castto(int64)}
const getdents64 = {fd, buf; -> syscall(Sysgetdents64, a(fd), buf castto(byte#), a(buf.len))}
const chdir = {dir; -> syscall(Syschdir, cstring(dir))}
+const getcwd = {buf; -> syscall(Sysgetcwd, a(buf), a(buf.len))}
/* file stuff */
const pipe = {fds; -> syscall(Syspipe, a(fds))}
diff --git a/libstd/syswrap+posixy.myr b/libstd/syswrap+posixy.myr
index e5fd6d1..c426d1f 100644
--- a/libstd/syswrap+posixy.myr
+++ b/libstd/syswrap+posixy.myr
@@ -2,6 +2,7 @@ use sys
use "cstrconv.use"
use "option.use"
use "types.use"
+use "errno.use"
pkg std =
type fd = sys.fd
@@ -52,8 +53,8 @@ pkg std =
/* path manipulation */
const mkdir : (path : byte[:], mode : int64 -> int64)
- const chdir : (path : byte[:] -> bool)
const remove : (path : byte[:] -> bool)
+ const chdir : (path : byte[:] -> bool)
/* process stuff */
const getpid : ( -> pid)
@@ -67,6 +68,7 @@ pkg std =
pkglocal const getmem : (sz : size -> byte#)
pkglocal const freemem : (p : byte#, sz : size -> void)
pkglocal const curtime : (-> time)
+ pkglocal const bgetcwd : (buf : byte[:] -> errno)
;;
/* fd stuff */
@@ -84,6 +86,7 @@ const dup2 = {ofd, nfd; -> sys.dup2(ofd castto(sys.fd), nfd castto(sys.fd)) cast
const mkdir = {path, mode; -> sys.mkdir(path, mode)}
const chdir = {path; -> sys.chdir(path) == 0}
const remove = {path; -> sys.unlink(path) == 0}
+const bgetcwd = {buf; -> sys.getcwd(buf) castto(errno)}
/* useful/portable bits of uname */
const getsysinfo = {si