summaryrefslogtreecommitdiff
path: root/libstd/getcwd.myr
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
commitd3672bb4f2ef344e41ff7fd3cb8c801a8edc6513 (patch)
tree33d73c65560e88413228057adb8991c2d7f38b07 /libstd/getcwd.myr
parentb8739b70c8fbb2f8930c7cb2b1d1a6544aa7024f (diff)
downloadmc-d3672bb4f2ef344e41ff7fd3cb8c801a8edc6513.tar.gz
Implement getcwd() on Linux.
This is needed for the newest mbld.
Diffstat (limited to 'libstd/getcwd.myr')
-rw-r--r--libstd/getcwd.myr30
1 files changed, 30 insertions, 0 deletions
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
+ ;;
+ ;;
+}
+