Index: kio/io.h ================================================================== --- kio/io.h +++ kio/io.h @@ -55,13 +55,24 @@ * select explicitly against kiocond_ok or kiocond_partial, since * those situations will usually need to be handled differently. */ kiocond_ok, // success kiocond_partial, // partial read or write + kiocond_poll, // call would block + kiocond_interrupt, // call was interrupted by signal kiocond_fail, // action failed - unspecified reason kiocond_fail_closed_stream, // action failed because stream is closed + kiocond_fail_invalid, + kiocond_fail_io, + kiocond_fail_no_peer, + kiocond_fail_no_space, + kiocond_fail_forbidden, + kiocond_fail_over_quota, + kiocond_fail_pfault, + kiocond_fail_too_big, + kiocond_fail_stream_mismatch, } kiocond; kiocond kiosend(kiochan, ksraw, sz*); // send data to a channel kiocond kiorecv(kiochan, ksraw*); // receive data from a channel kmptr kiorecvall(kiochan, kmcell*, kmkind); // automatically allocate a bufer for a channel Index: kio/send.fn.c ================================================================== --- kio/send.fn.c +++ kio/send.fn.c @@ -9,10 +9,11 @@ /* we define all platform functions here, * whether or not they're for the correct * platform - only the ones actually called * by the generated code will be linked */ #include +#include kiocond kiosend(kiochan target, ksraw string, sz* len) { if (target.out.kind == kiostream_closed) return kiocond_fail_closed_stream; # ifdef KFenv_posix @@ -24,11 +25,24 @@ struct k_platform_syscall_answer a = k_platform_syscall (k_platform_syscall_write,3,args); sz size = a.ret; - if (size == -1) return kiocond_fail; //TODO: retrieve errno and offer more specific errors + if (size == -1) switch(a.error) { + case k_platform_error_EPERM: return kiocond_fail_forbidden; + case k_platform_error_EINVAL: return kiocond_fail_invalid; + case k_platform_error_EBADF: return kiocond_fail_invalid; + case k_platform_error_EFAULT: return kiocond_fail_pfault; + case k_platform_error_ENOSPC: return kiocond_fail_no_space; + case k_platform_error_EDQUOT: return kiocond_fail_over_quota; + case k_platform_error_EIO: return kiocond_fail_io; + case k_platform_error_EAGAIN: return kiocond_poll; + case k_platform_error_EFBIG: return kiocond_fail_too_big; + case k_platform_error_EINTR: return kiocond_interrupt; + case k_platform_error_EDESTADDRREQ: return kiocond_fail_no_peer; + default: return kiocond_fail; + } # else # if KVos == win # error windows IO send function not yet defined # else Knoimpl(kiosend,KVos); Index: makefile ================================================================== --- makefile +++ makefile @@ -3,11 +3,11 @@ # TODO: calculate these using $(MAKE_HOST) export ARCH = x86 export OS = lin export BITS = 64 export ROOT = $(PWD) -export TMP = $(PWD)/tmp +export TMP = $(PWD)/gen ifneq ($(BITS),) export TARGET = $(ARCH).$(OS).$(BITS) else export TARGET = $(ARCH).$(OS) @@ -92,25 +92,32 @@ lists = moddirs functions assemblies fnobjects rtobjects binaries binmods POSIX dbg: @echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))") -%.obj: %/makefile $(TMP)/system_calls.h $(TMP)/system_calls.s $(OUT) +%.obj: %/makefile $(OUT) cd $* && $(MAKE) obj %.tool: %/makefile $(OUT) cd $* && $(MAKE) tool %.dbg: %/makefile $(OUT) cd $* && $(MAKE) dbg -%.def: %/makefile $(TMP)/typesize.def $(OUT) $(OUT)/k +%.def: %/makefile $(TMP)/typesize.def \ + $(TMP)/system_calls.h \ + $(TMP)/system_calls.s \ + $(TMP)/error_table.h \ + $(OUT) $(OUT)/k cd $* && $(MAKE) def .PRECIOUS: $(TMP)/system_calls.% $(TMP)/system_calls.%: arch/makefile $(MAKE) -C arch $@ + +$(TMP)/error_table.h: arch/makefile + $(MAKE) -C arch $@ $(TMP)/typesize.def: arch/makefile $(TMP) $(MAKE) -C arch $@ $(OUT)/libk.so: $(fnobjects)