authorgravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-03-15 17:57:56-07:00
committergravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-03-15 17:57:56-07:00
log4c16deed3ef4f3c4695deb32a6e7c1174bd38bd9
tree9e9985d50e7d5bba6f48c24d2d84c85890ca5240
parent681c62941e9219b475c2e441e360c0c72cd6ccdc

Some POSIX stuff, including a primitive write


1 files changed, 40 insertions(+), 3 deletions(-)

std/os/zen.zig+40-3
...@@ -7,13 +7,21 @@ pub const Message = struct {...@@ -7,13 +7,21 @@ pub const Message = struct {
7 receiver: MailboxId,7 receiver: MailboxId,
8 payload: usize,8 payload: usize,
99
10 pub fn withReceiver(mailbox_id: &const MailboxId) Message {10 pub fn from(mailbox_id: &const MailboxId) Message {
11 return Message {11 return Message {
12 .sender = undefined,12 .sender = undefined,
13 .receiver = *mailbox_id,13 .receiver = *mailbox_id,
14 .payload = undefined,14 .payload = undefined,
15 };15 };
16 }16 }
17
18 pub fn to(mailbox_id: &const MailboxId, payload: usize) Message {
19 return Message {
20 .sender = MailboxId.This,
21 .receiver = *mailbox_id,
22 .payload = payload,
23 };
24 }
17};25};
1826
19pub const MailboxId = union(enum) {27pub const MailboxId = union(enum) {
...@@ -29,11 +37,40 @@ pub const MailboxId = union(enum) {...@@ -29,11 +37,40 @@ pub const MailboxId = union(enum) {
29///////////////////////////////////////37///////////////////////////////////////
3038
31pub const Service = struct {39pub const Service = struct {
32 pub const Terminal = MailboxId { .Port = 0 };40 pub const Keyboard = MailboxId { .Port = 0 };
33 pub const Keyboard = MailboxId { .Port = 1 };41 pub const Terminal = MailboxId { .Port = 1 };
34};42};
3543
3644
45////////////////////////
46//// POSIX things ////
47////////////////////////
48
49// Standard streams.
50pub const STDIN_FILENO = 0;
51pub const STDOUT_FILENO = 1;
52pub const STDERR_FILENO = 2;
53
54// FIXME: let's borrow Linux's error numbers for now.
55pub const getErrno = @import("linux/index.zig").getErrno;
56use @import("linux/errno.zig");
57
58// TODO: implement this correctly.
59pub fn write(fd: i32, buf: &const u8, count: usize) usize {
60 switch (fd) {
61 STDIN_FILENO => unreachable,
62 STDOUT_FILENO, STDERR_FILENO => {
63 var i: usize = 0;
64 while (i < count) : (i += 1) {
65 send(Message.to(Service.Terminal, buf[i]));
66 }
67 },
68 else => unreachable,
69 }
70 return count;
71}
72
73
37///////////////////////////74///////////////////////////
38//// Syscall numbers ////75//// Syscall numbers ////
39///////////////////////////76///////////////////////////