libk  Diff

Differences From Artifact [5cc5cc2649]:

To Artifact [0bd4793a38]:


     6      6    * kiosend() writes to a channel with an open out stream
     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         -extern sz kio_posix_fd_write(int fd, const char* buf, sz len);
           13  +#include <posix.h>
    14     14   
    15     15   kiocond kiosend(kiochan target, ksraw string, sz* len) {
    16     16   	if (target.out.kind == kiostream_closed) return kiocond_fail_closed_stream;
    17     17   
    18     18   #	ifdef KFenv_posix
    19         -		sz size = kio_posix_fd_write(target.out.platform_fd, string.ptr, string.size);
           19  +		/* issue the write syscall here and now so we can
           20  +		 * retrieve errno and report it if necessary */
           21  +
           22  +		k_platform_syscall_arg args[] = {
           23  +			target.out.platform_fd, (k_platform_syscall_arg)string.ptr, string.size };
           24  +
           25  +		struct k_platform_syscall_answer a = k_platform_syscall
           26  +			(k_platform_syscall_write,3,args);
           27  +
           28  +		sz size = a.ret;
    20     29   		if (size == -1) return kiocond_fail; //TODO: retrieve errno and offer more specific errors
    21     30   #	else
    22     31   #		if KVos == win
    23     32   #			error windows IO send function not yet defined
    24     33   #		else
    25     34   			Knoimpl(kiosend,KVos);
    26     35   #			error missing implementation // boring error for plebs
    27     36   #		endif
    28     37   #	endif
    29     38   
    30     39   	if (len != null) *len = size;
    31     40   	return kiocond_ok;
    32     41   }