| ... | @@ -13,8 +13,8 @@ sender: MailboxId, | ... | @@ -13,8 +13,8 @@ sender: MailboxId, |
| 13 | payload: ?[]const u8, | 13 | payload: ?[]const u8, |
| 14 | | 14 | |
| 15 | pub fn from(mailbox_id: *const MailboxId) Message { | 15 | pub fn from(mailbox_id: *const MailboxId) Message { |
| 16 | return Message{ | 16 | return Message { |
| 17 | .sender = MailboxId.Undefined, | 17 | .sender = MailboxId.Undefined, |
| 18 | .receiver = mailbox_id.*, | 18 | .receiver = mailbox_id.*, |
| 19 | .code = undefined, | 19 | .code = undefined, |
| 20 | .args = undefined, | 20 | .args = undefined, |
| ... | @@ -80,11 +80,15 @@ pub const STDOUT_FILENO = 1; | ... | @@ -80,11 +80,15 @@ pub const STDOUT_FILENO = 1; |
| 80 | pub const STDERR_FILENO = 2; | 80 | pub const STDERR_FILENO = 2; |
| 81 | | 81 | |
| 82 | // FIXME: let's borrow Linux's error numbers for now. | 82 | // FIXME: let's borrow Linux's error numbers for now. |
| 83 | pub const getErrno = @import("linux/index.zig").getErrno; | | |
| 84 | use @import("linux/errno.zig"); | 83 | use @import("linux/errno.zig"); |
| | 84 | // Get the errno from a syscall return value, or 0 for no error. |
| | 85 | pub fn getErrno(r: usize) usize { |
| | 86 | const signed_r = @bitCast(isize, r); |
| | 87 | return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; |
| | 88 | } |
| 85 | | 89 | |
| 86 | // TODO: implement this correctly. | 90 | // TODO: implement this correctly. |
| 87 | pub fn read(fd: i32, buf: *u8, count: usize) usize { | 91 | pub fn read(fd: i32, buf: [*]u8, count: usize) usize { |
| 88 | switch (fd) { | 92 | switch (fd) { |
| 89 | STDIN_FILENO => { | 93 | STDIN_FILENO => { |
| 90 | var i: usize = 0; | 94 | var i: usize = 0; |
| ... | @@ -93,9 +97,9 @@ pub fn read(fd: i32, buf: *u8, count: usize) usize { | ... | @@ -93,9 +97,9 @@ pub fn read(fd: i32, buf: *u8, count: usize) usize { |
| 93 | | 97 | |
| 94 | // FIXME: we should be certain that we are receiving from Keyboard. | 98 | // FIXME: we should be certain that we are receiving from Keyboard. |
| 95 | var message = Message.from(MailboxId.This); | 99 | var message = Message.from(MailboxId.This); |
| 96 | receive(message.*); | 100 | receive(&message); |
| 97 | | 101 | |
| 98 | buf[i] = u8(message.args[0]); | 102 | buf[i] = @intCast(u8, message.args[0]); |
| 99 | } | 103 | } |
| 100 | }, | 104 | }, |
| 101 | else => unreachable, | 105 | else => unreachable, |
| ... | @@ -104,7 +108,7 @@ pub fn read(fd: i32, buf: *u8, count: usize) usize { | ... | @@ -104,7 +108,7 @@ pub fn read(fd: i32, buf: *u8, count: usize) usize { |
| 104 | } | 108 | } |
| 105 | | 109 | |
| 106 | // TODO: implement this correctly. | 110 | // TODO: implement this correctly. |
| 107 | pub fn write(fd: i32, buf: *const u8, count: usize) usize { | 111 | pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { |
| 108 | switch (fd) { | 112 | switch (fd) { |
| 109 | STDOUT_FILENO, STDERR_FILENO => { | 113 | STDOUT_FILENO, STDERR_FILENO => { |
| 110 | send(Message.to(Server.Terminal, 1) | 114 | send(Message.to(Server.Terminal, 1) |