libk  Diff

Differences From Artifact [0bd4793a38]:

To Artifact [f571b39492]:


7
8
9
10
11
12
13

14
15
16
17
18
19
20
..
22
23
24
25
26
27
28
29













30
31
32
33
34
35
36
37
38
39
40
41
 */

/* 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 <posix.h>


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

#	ifdef KFenv_posix
		/* issue the write syscall here and now so we can
		 * retrieve errno and report it if necessary */
................................................................................
		k_platform_syscall_arg args[] = {
			target.out.platform_fd, (k_platform_syscall_arg)string.ptr, string.size };

		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













#	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;
}







>







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>












7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 */

/* 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 <posix.h>
#include <error_table.h>

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

#	ifdef KFenv_posix
		/* issue the write syscall here and now so we can
		 * retrieve errno and report it if necessary */
................................................................................
		k_platform_syscall_arg args[] = {
			target.out.platform_fd, (k_platform_syscall_arg)string.ptr, string.size };

		struct k_platform_syscall_answer a = k_platform_syscall
			(k_platform_syscall_write,3,args);

		sz size = a.ret;
		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);
#			error missing implementation // boring error for plebs
#		endif
#	endif

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