shithub: mc

ref: 3ccf3f0a5e3c33e3722a9ea29134ea5a7dacf041
dir: /libstd/cstrconv.myr/

View raw version
use "types.use"

pkg std =
	const cstrconv	: (buf : byte[:] -> byte[:])
	const cstrconvp	: (p : byte# -> byte[:])
;;

const cstrconv = {buf
	var i

	for i = 0; i < buf.len; i++
		if buf[i] == 0
			-> buf[:i]
		;;
	;;
	-> buf
}

const cstrconvp = {p
	var i, base

	i = 0
	base = p castto(intptr)
	while ((base + i) castto(byte#))# != 0
		i++
	;;
	-> p[:i]
}