little_os_posix.ltl - LITTLE part of Posix toys


	(package little.os ()
		(method init () :static
			(System:loadlib 'little_os)
			(Posix:load)))

	(class Posix (OS)

		(method init () :static:local:native)

		(method fork () :native)

		(method exec (name args) :hidden:native)

		(method exec (args)
			(let ((_args (Array:new (args:size))) (i 0))
				(for (arg args)
					(_args:put i (arg:getbuffer))
					(set i (i:succ)))
				(self:exec (_args:get 0) _args)))

	)

  

little_os_posix.c - Native Implementation


	#include <little/little.h>
	#include <little/little_rt.h>
	#include <little/little_lang_Array.h>
	#include <unistd.h>

	static ltl_sym_t array_class = -1;
	static ltl_sym_t strbuf_class = -1;

	LTL_METHOD_DECL(little_os_MetaPosix_init_0)
	{
		LTL_ASSERT_CLASS(array_class,ARRAY_CLASS);
		LTL_ASSERT_CLASS(strbuf_class,STRBUF_CLASS);
		LTL_RETURN(LTL_NIL);
	}

	LTL_METHOD_DECL(little_os_Posix_fork_0)
	{
		LTL_RETURN_SPECIAL(LTL_TYPE_WORD,fork());
	}

	LTL_METHOD_DECL(little_os_Posix_exec_2)
	{
		char **args = NULL;
		ltl_object_t *o_size = LTL_LOCAL(),
				     *o_item = LTL_LOCAL(),
					 *o_i = LTL_LOCAL(),
					 *o_name = LTL_ARG(0),
					 *o_argv = LTL_ARG(1);
		int size = 0, i = 0;
		LTL_CHECK_ARG(0,strbuf_class,"little_lang_os_Posix_exec_2");
		LTL_CHECK_ARG(1,array_class,"little_lang_os_Posix_exec_2");
		o_size = ltl_little_lang_Array_size_0(threadenv,o_argv);
		size = (int) LTL_OBJECT_FIELD(o_size,0);
		args = ltl_malloc(sizeof(char *) * (size+1));
		for ( ; i<size; i++ ) {
			LTL_OBJECT_SETSPECIAL(o_i,LTL_TYPE_WORD,i);
			o_item = ltl_little_lang_Array_get_1(threadenv,o_argv,o_i);
			args[i] = LTL_STRBUF_PCHAR(o_item);
		}
		args[i] = NULL;
		LTL_RETURN_SPECIAL(LTL_TYPE_WORD,execvp(LTL_STRBUF_PCHAR(o_name),args));
	}