summaryrefslogtreecommitdiff
path: root/lib/std/syswrap-ss+osx.myr
blob: 53a1db1ec17fa236626818a18bfabad6f8c77963 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use sys
use "errno"
use "cstrconv"
use "slcp"
use "die"

pkg std =
	const nanosleep	: (nsecs : uint64 -> errno)
	$noret const exit	: (status:int -> void)

	pkglocal const bgetcwd	: (buf : byte[:] -> errno)
;;


extern const put	: (fmt : byte[:], args : ... -> int64)

const nanosleep	= {nsecs
	var s, us

	s = (nsecs / 1_000_000_000 : int64)
	us = (nsecs % 1_000_000_000 / 1000 : int32)
	-> (sys.select( \
		0, \
		(0 : sys.fdset#), \
		(0 : sys.fdset#), \
		(0 : sys.fdset#), \
		&[.sec = s, .usec = us] \
	) : errno)
}

const exit	= {status;
	sys.exit(status)
}

const bgetcwd	= {buf
	var path : byte[sys.Maxpathlen]
	var fd, len, err

	fd = sys.open(".", sys.Ordonly)
	if fd < 0
		-> (fd : errno)
	;;
	/* 
	FIXME: if the path is longer than sys.Pathmax, we should fall back to
	the ugly method of finding the path.
	*/
	err = (sys.fcntl(fd, sys.Fgetpath, (path[:] : byte#)) : errno)
	if err < 0
		-> err
	;;
	len = cstrlen(path[:])
	if len >= buf.len
		-> Erange
	;;
	slcp(buf[:len], path[:len])
	-> (len : errno)
}