libk  boot.rt.c at [5f66b55640]

File mod/kcore/boot.rt.c artifact 7899b05286 part of check-in 5f66b55640


#include <k/core.h>
#include <k/type.h>
extern stat entry(kenv);

unsigned long long
_boot(unsigned int argc, /* argument count */
		char** argv, /* arguments */
		char** envp /* environment */ ) {

	envp ++; /* envp seems to point at a leading null;
				this is probably a sign of breakage but
				i don't know what else to do about it for
				the moment. */

	char** ep;
	/* advance ep until it points at the last element */
	for (ep = envp; *ep != 0; ++ep);

	/* allocate space for each environment variable */
	kvar variables [ep - envp];

	for (char** v = envp; *v != 0; ++v) {
		kvar* var = variables + (v - envp);
		var -> name.ptr = *v;
		char* i = *v;
		for(;*i != '=';++i);
		var -> name.size = i - *v;
		var -> val.ptr = i + 1;
		for(;*i != 0;++i);

		/* there is probably a better way to do this; my
		 * brain is too foggy to figure one out tho */
		var -> val.size = (i - *v) - var -> name.size;
	}

	kenv e = { 
		/* TODO: determine terminal class and set term vs ansi correctly! */
		{ {kiostream_term, 0}, {kiostream_term, 1} }, // chan std
		{ {kiostream_closed},  {kiostream_term, 2} }, // chan err
		argc, argv, ep - envp, variables
	};
	return entry(e);
}