diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-01-07 03:23:38 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-01-07 03:23:38 -0700 |
| commit | a3c97081ca37a6f78732c9a5f2244cef5a11cb07 (patch) | |
| tree | aec69a113eacaa084039364b65ef803d695e0dd5 /std | |
| parent | 9b9fd5ad23e37d1e2b37b05b168abcfd53f4629d (diff) | |
| download | zig-a3c97081ca37a6f78732c9a5f2244cef5a11cb07.tar.gz zig-a3c97081ca37a6f78732c9a5f2244cef5a11cb07.zip | |
add ?? maybe unwrapping binary operator
add null literal
fix number literal / maybe interactions
Diffstat (limited to 'std')
| -rw-r--r-- | std/std.zig | 21 | ||||
| -rw-r--r-- | std/syscall.zig | 5 |
2 files changed, 26 insertions, 0 deletions
diff --git a/std/std.zig b/std/std.zig index a53dbb6027..333896cadc 100644 --- a/std/std.zig +++ b/std/std.zig @@ -1,5 +1,6 @@ use "syscall.zig"; +const stdin_fileno : isize = 0; const stdout_fileno : isize = 1; const stderr_fileno : isize = 2; @@ -38,6 +39,26 @@ pub fn print_i64(x: i64) -> isize { return write(stdout_fileno, buf.ptr, len); } +/* +// TODO error handling +pub fn readline(buf: []u8) -> ?[]u8 { + var index = 0; + while (index < buf.len) { + // TODO unknown size array indexing operator + const err = read(stdin_fileno, &buf.ptr[index], 1); + if (err != 0) { + return null; + } + // TODO unknown size array indexing operator + if (buf.ptr[index] == '\n') { + return buf[0...index + 1]; + } + index += 1; + } + return null; +} +*/ + fn digit_to_char(digit: u64) -> u8 { '0' + (digit as u8) } diff --git a/std/syscall.zig b/std/syscall.zig index 1bcbcdbe31..97542363cb 100644 --- a/std/syscall.zig +++ b/std/syscall.zig @@ -1,3 +1,4 @@ +const SYS_read : usize = 0; const SYS_write : usize = 1; const SYS_exit : usize = 60; const SYS_getrandom : usize = 318; @@ -16,6 +17,10 @@ fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { : "rcx", "r11") } +pub fn read(fd: isize, buf: &u8, count: usize) -> isize { + syscall3(SYS_read, fd as usize, buf as usize, count) as isize +} + pub fn write(fd: isize, buf: &const u8, count: usize) -> isize { syscall3(SYS_write, fd as usize, buf as usize, count) as isize } |
