libk  testbin.exe.c at [49da7c1eeb]

File mod/kcore/testbin.exe.c artifact b799b010e3 part of check-in 49da7c1eeb


#include <k/core.h>
#include <k/mem.h>
#include <k/io.h>
#include <k/magic.h>

struct object {
	u8 a;
	s16 b;
	bool c;
};

#define _slit(s) ((ksraw){Kmsz(s) - 1,s})

kbad entry(kenv e) {
	const char msg[] = "hello from libk\n";
	ksraw ptr = { Kmsz(msg) - 1, msg };

	bool maybe = true;
	maybe = no;

	if (kiosend(e.std, ptr, null) == kiocond_ok) {
		/* great, continue */
	} else {
		return kbad_io;
	}

	kmres alloc = kmheapa(2048);
	if (alloc.cond != kmcond_ok) return kbad_mem;
	
	void* region = alloc.raw;
	kmzero(region,2048);

	if (kmheapf(region) >= kmcond_fail) return kbad_mem;

	void* top = kmlini();
	kmres rst = kmlina(1230);
	if(rst.cond != kmcond_ok) return kbad_mem;

	kmres rst2 = kmlina(789);
	if(rst2.cond != kmcond_ok) return kbad_mem;

	kiosend(e.std,  _slit("printing environment variables\n"), null);

	for (sz i = 0; i < e.varc; ++i) {
		kiosend(e.std, _slit(" - "), null);
		kiosend(e.std, e.vars[i].name, null);
		kiosend(e.std, _slit(" = ["), null);
		kiosend(e.std, e.vars[i].val, null);
		kiosend(e.std, _slit("]\n"), null);
	}

	return kbad_ok;
}