diff options
Diffstat (limited to 'std')
| -rw-r--r-- | std/io.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/std/io.zig b/std/io.zig index 952d9081f2..93d50e6709 100644 --- a/std/io.zig +++ b/std/io.zig @@ -478,3 +478,20 @@ test "import io tests" { } } +pub fn readLine(buf: []u8) !usize { + var stdin = getStdIn() catch return error.StdInUnavailable; + var adapter = FileInStream.init(&stdin); + var stream = &adapter.stream; + var index: usize = 0; + while (true) { + const byte = stream.readByte() catch return error.EndOfFile; + switch (byte) { + '\n' => return index, + else => { + if (index == buf.len) return error.InputTooLong; + buf[index] = byte; + index += 1; + }, + } + } +} |
