| ... | ... | @@ -4,7 +4,6 @@ pub const STDIN_FILENO = 0; |
| 4 | 4 | pub const STDOUT_FILENO = 1; |
| 5 | 5 | pub const STDERR_FILENO = 2; |
| 6 | 6 | |
| 7 | | // TODO: implement this like darwin does |
| 8 | 7 | pub fn getErrno(r: usize) usize { |
| 9 | 8 | const signed_r = @bitCast(isize, r); |
| 10 | 9 | return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; |
| ... | ... | @@ -13,11 +12,31 @@ pub fn getErrno(r: usize) usize { |
| 13 | 12 | pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { |
| 14 | 13 | var nwritten: usize = undefined; |
| 15 | 14 | |
| 16 | | const iovs = []ciovec_t{ciovec_t{ |
| 15 | const ciovs = ciovec_t{ |
| 17 | 16 | .buf = buf, |
| 18 | 17 | .buf_len = count, |
| 19 | | }}; |
| 18 | }; |
| 20 | 19 | |
| 21 | | _ = fd_write(@bitCast(fd_t, isize(fd)), &iovs[0], iovs.len, &nwritten); |
| 22 | | return nwritten; |
| 20 | const err = fd_write(@bitCast(fd_t, isize(fd)), &ciovs, 1, &nwritten); |
| 21 | if (err == ESUCCESS) { |
| 22 | return nwritten; |
| 23 | } else { |
| 24 | return @bitCast(usize, -isize(err)); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | pub fn read(fd: i32, buf: [*]u8, nbyte: usize) usize { |
| 29 | var nread: usize = undefined; |
| 30 | |
| 31 | const iovs = iovec_t{ |
| 32 | .buf = buf, |
| 33 | .buf_len = nbyte, |
| 34 | }; |
| 35 | |
| 36 | const err = fd_read(@bitCast(fd_t, isize(fd)), &iovs, 1, &nread); |
| 37 | if (err == ESUCCESS) { |
| 38 | return nread; |
| 39 | } else { |
| 40 | return @bitCast(usize, -isize(err)); |
| 41 | } |
| 23 | 42 | } |