diff options
Diffstat (limited to 'lib/std/getcwd.myr')
-rw-r--r-- | lib/std/getcwd.myr | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/std/getcwd.myr b/lib/std/getcwd.myr new file mode 100644 index 0000000..c9dbbea --- /dev/null +++ b/lib/std/getcwd.myr @@ -0,0 +1,31 @@ + +use "alloc.use" +use "errno.use" +use "extremum.use" +use "syswrap.use" +use "syswrap-ss.use" +pkg std = + const getcwd : (-> byte[:]) +;; + +const getcwd = { + var len, n, buf + + len = 128 + while true + buf = std.slalloc(len) + n = bgetcwd(buf) + if n >= 0 + /* n is the length of the nul terminated c string */ + -> buf[:n] + elif n != Erange + std.slfree(buf) + -> "" + else + len *= 2 + ;; + ;; + /* unreachable; shut up return without value analysis */ + -> "" +} + |