diff options
| author | Andrea Orru <andrea@orru.io> | 2018-03-15 17:57:56 -0700 |
|---|---|---|
| committer | Andrea Orru <andrea@orru.io> | 2018-03-15 17:57:56 -0700 |
| commit | 4c16deed3ef4f3c4695deb32a6e7c1174bd38bd9 (patch) | |
| tree | 9e9985d50e7d5bba6f48c24d2d84c85890ca5240 /std | |
| parent | 681c62941e9219b475c2e441e360c0c72cd6ccdc (diff) | |
| download | zig-4c16deed3ef4f3c4695deb32a6e7c1174bd38bd9.tar.gz zig-4c16deed3ef4f3c4695deb32a6e7c1174bd38bd9.zip | |
Some POSIX stuff, including a primitive write
Diffstat (limited to 'std')
| -rw-r--r-- | std/os/zen.zig | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/std/os/zen.zig b/std/os/zen.zig index 94d470d70f..37c674c9e1 100644 --- a/std/os/zen.zig +++ b/std/os/zen.zig @@ -7,13 +7,21 @@ pub const Message = struct { receiver: MailboxId, payload: usize, - pub fn withReceiver(mailbox_id: &const MailboxId) Message { + pub fn from(mailbox_id: &const MailboxId) Message { return Message { .sender = undefined, .receiver = *mailbox_id, .payload = undefined, }; } + + pub fn to(mailbox_id: &const MailboxId, payload: usize) Message { + return Message { + .sender = MailboxId.This, + .receiver = *mailbox_id, + .payload = payload, + }; + } }; pub const MailboxId = union(enum) { @@ -29,11 +37,40 @@ pub const MailboxId = union(enum) { /////////////////////////////////////// pub const Service = struct { - pub const Terminal = MailboxId { .Port = 0 }; - pub const Keyboard = MailboxId { .Port = 1 }; + pub const Keyboard = MailboxId { .Port = 0 }; + pub const Terminal = MailboxId { .Port = 1 }; }; +//////////////////////// +//// POSIX things //// +//////////////////////// + +// Standard streams. +pub const STDIN_FILENO = 0; +pub const STDOUT_FILENO = 1; +pub const STDERR_FILENO = 2; + +// FIXME: let's borrow Linux's error numbers for now. +pub const getErrno = @import("linux/index.zig").getErrno; +use @import("linux/errno.zig"); + +// TODO: implement this correctly. +pub fn write(fd: i32, buf: &const u8, count: usize) usize { + switch (fd) { + STDIN_FILENO => unreachable, + STDOUT_FILENO, STDERR_FILENO => { + var i: usize = 0; + while (i < count) : (i += 1) { + send(Message.to(Service.Terminal, buf[i])); + } + }, + else => unreachable, + } + return count; +} + + /////////////////////////// //// Syscall numbers //// /////////////////////////// |
