libk  Diff

Differences From Artifact [430158e543]:

To Artifact [5cc5cc2649]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <k/io.h>
#include <k/core.h>
#include <k/def.h>
/* send.c - kiosend()
 * ~ lexi hale <lexi@hale.su>
 * kiosend() writes to a channel with an open out stream
 */

// 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
extern sz kio_posix_fd_write(int fd, const char* buf, sz len);

kiocond kiosend(kiochan target, ksraw string, sz* len) {


#	ifdef KFenv_posix
		sz size = kio_posix_fd_write(target.out.platform_fd, string.ptr, string.size);
		if (size == -1) return kiocond_fail; //TODO: retrieve errno and offer more specific errors
#	else
#		if KVos == win
#			error windows IO send function not yet defined
#		else
			_Pragma("GCC diagnostic error \"" // fancy error for gcc
				"IO send fn for platform " #KVos " not defined"
			"\""))
#			error IO send fn not defined for platform
			   // boring error for plebs
#		endif
#	endif

	if (len != null) *len = size;
	return kiocond_ok;
}



|




|
|
|
|



>
>







|
<
<
<
|






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25



26
27
28
29
30
31
32
#include <k/io.h>
#include <k/core.h>
#include <k/def.h>
/* send.c - kiosend() "send to channel"
 * ~ lexi hale <lexi@hale.su>
 * kiosend() writes to a channel with an open out stream
 */

/* 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 */
extern sz kio_posix_fd_write(int fd, const char* buf, sz len);

kiocond kiosend(kiochan target, ksraw string, sz* len) {
	if (target.out.kind == kiostream_closed) return kiocond_fail_closed_stream;

#	ifdef KFenv_posix
		sz size = kio_posix_fd_write(target.out.platform_fd, string.ptr, string.size);
		if (size == -1) return kiocond_fail; //TODO: retrieve errno and offer more specific errors
#	else
#		if KVos == win
#			error windows IO send function not yet defined
#		else
			Knoimpl(kiosend,KVos);



#			error missing implementation // boring error for plebs
#		endif
#	endif

	if (len != null) *len = size;
	return kiocond_ok;
}