shithub: mc

ref: dfe28e0a978ca1acb738b2718a3ef2bd1617ed9a
dir: /libstd/getcwd.myr/

View raw version

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
		;;
	;;
}