~sircmpwn/hare unlisted

57876d3449a48dfd9e05c139882b85542ab9b8f5 — Drew DeVault 2 months ago c70a3fb
sys::hart1: improve str_from_cstr code
1 files changed, 7 insertions(+), 6 deletions(-)

M lib/sys/hart1.ha
M lib/sys/hart1.ha => lib/sys/hart1.ha +7 -6
@@ 15,18 15,19 @@ fn cstr_len(cstr: *char) size =
fn str_from_cstr(cstr: *char) &str =
{
	const l = cstr_len(cstr);
	let s = must_malloc(size(size) + l + 1): uintptr;

	let sz = s: *size;
	*sz = l;
	let s = must_malloc(size(size) + l + 1): &struct {
		sz: size,
		data: u8,
	};
	s.sz = l;

	const in = cstr: [*]u8;
	let out = (s + size(size)): [*]u8;
	let out = &s.data: [*]u8;
	for (let i = 0; i <= l; i += 1) {
		out[i] = in[i];
	};

	s: &str;
	^s: &str;
};

export fn start_ha(iv: [*]uintptr) void =