blob: c9dbbea9e435048fff76690a30108e83b76ad765 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 */
-> ""
}
|