libk  Diff

Differences From Artifact [0bd4793a38]:

To Artifact [f571b39492]:


     7      7    */
     8      8   
     9      9   /* we define all platform functions here,
    10     10    * whether or not they're for the correct
    11     11    * platform - only the ones actually called
    12     12    * by the generated code will be linked */
    13     13   #include <posix.h>
           14  +#include <error_table.h>
    14     15   
    15     16   kiocond kiosend(kiochan target, ksraw string, sz* len) {
    16     17   	if (target.out.kind == kiostream_closed) return kiocond_fail_closed_stream;
    17     18   
    18     19   #	ifdef KFenv_posix
    19     20   		/* issue the write syscall here and now so we can
    20     21   		 * retrieve errno and report it if necessary */
................................................................................
    22     23   		k_platform_syscall_arg args[] = {
    23     24   			target.out.platform_fd, (k_platform_syscall_arg)string.ptr, string.size };
    24     25   
    25     26   		struct k_platform_syscall_answer a = k_platform_syscall
    26     27   			(k_platform_syscall_write,3,args);
    27     28   
    28     29   		sz size = a.ret;
    29         -		if (size == -1) return kiocond_fail; //TODO: retrieve errno and offer more specific errors
           30  +		if (size == -1) switch(a.error) {
           31  +			case k_platform_error_EPERM:  return kiocond_fail_forbidden;
           32  +			case k_platform_error_EINVAL: return kiocond_fail_invalid;
           33  +			case k_platform_error_EBADF:  return kiocond_fail_invalid;
           34  +			case k_platform_error_EFAULT: return kiocond_fail_pfault;
           35  +			case k_platform_error_ENOSPC: return kiocond_fail_no_space;
           36  +			case k_platform_error_EDQUOT: return kiocond_fail_over_quota;
           37  +			case k_platform_error_EIO:    return kiocond_fail_io;
           38  +			case k_platform_error_EAGAIN: return kiocond_poll;
           39  +			case k_platform_error_EFBIG:  return kiocond_fail_too_big;
           40  +			case k_platform_error_EINTR:  return kiocond_interrupt;
           41  +			case k_platform_error_EDESTADDRREQ: return kiocond_fail_no_peer;
           42  +			default: return kiocond_fail;
           43  +		}
    30     44   #	else
    31     45   #		if KVos == win
    32     46   #			error windows IO send function not yet defined
    33     47   #		else
    34     48   			Knoimpl(kiosend,KVos);
    35     49   #			error missing implementation // boring error for plebs
    36     50   #		endif
    37     51   #	endif
    38     52   
    39     53   	if (len != null) *len = size;
    40     54   	return kiocond_ok;
    41     55   }