libk  Diff

Differences From Artifact [430158e543]:

To Artifact [5cc5cc2649]:


     1      1   #include <k/io.h>
     2      2   #include <k/core.h>
     3      3   #include <k/def.h>
     4         -/* send.c - kiosend()
            4  +/* send.c - kiosend() "send to channel"
     5      5    * ~ lexi hale <lexi@hale.su>
     6      6    * kiosend() writes to a channel with an open out stream
     7      7    */
     8      8   
     9         -// we define all platform functions here,
    10         -// whether or not they're for the correct
    11         -// platform - only the ones actually called
    12         -// by the generated code will be linked
            9  +/* we define all platform functions here,
           10  + * whether or not they're for the correct
           11  + * platform - only the ones actually called
           12  + * by the generated code will be linked */
    13     13   extern sz kio_posix_fd_write(int fd, const char* buf, sz len);
    14     14   
    15     15   kiocond kiosend(kiochan target, ksraw string, sz* len) {
           16  +	if (target.out.kind == kiostream_closed) return kiocond_fail_closed_stream;
           17  +
    16     18   #	ifdef KFenv_posix
    17     19   		sz size = kio_posix_fd_write(target.out.platform_fd, string.ptr, string.size);
    18     20   		if (size == -1) return kiocond_fail; //TODO: retrieve errno and offer more specific errors
    19     21   #	else
    20     22   #		if KVos == win
    21     23   #			error windows IO send function not yet defined
    22     24   #		else
    23         -			_Pragma("GCC diagnostic error \"" // fancy error for gcc
    24         -				"IO send fn for platform " #KVos " not defined"
    25         -			"\""))
    26         -#			error IO send fn not defined for platform
    27         -			   // boring error for plebs
           25  +			Knoimpl(kiosend,KVos);
           26  +#			error missing implementation // boring error for plebs
    28     27   #		endif
    29     28   #	endif
    30     29   
    31     30   	if (len != null) *len = size;
    32     31   	return kiocond_ok;
    33     32   }