shithub: mc

ref: ef16012a85da92aa8e7fdb7890e2f7a88364c9bd
dir: /lib/std/syswrap-ss+osx.myr/

View raw version
use sys
use "errno"
use "cstrconv"
use "slcp"
use "die"

pkg std =
	const exit	: (status:int -> void)
	pkglocal const bgetcwd	: (buf : byte[:] -> 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 castto(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[:] castto(byte#)) castto(errno)
	if err < 0
		-> err
	;;
	len = cstrlen(path[:])
	if len >= buf.len
		-> Erange
	;;
	slcp(buf[:len], path[:len])
	-> len castto(errno)
}