diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-04-24 12:01:19 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-04-24 12:14:45 -0400 |
| commit | 245eed8afee899cb0d0a2dac60c8a1edc6be654d (patch) | |
| tree | c8aae712c859577218e818350d82ba24500a2d4e /std/io.zig | |
| parent | 08a871f625aaf75ca47ea6bbc6304587c4bbae86 (diff) | |
| download | zig-245eed8afee899cb0d0a2dac60c8a1edc6be654d.tar.gz zig-245eed8afee899cb0d0a2dac60c8a1edc6be654d.zip | |
better stack traces for ELF x86_64
Diffstat (limited to 'std/io.zig')
| -rw-r--r-- | std/io.zig | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/std/io.zig b/std/io.zig index 2b48e1d899..0bf34acaa4 100644 --- a/std/io.zig +++ b/std/io.zig @@ -55,7 +55,7 @@ error NoDevice; error PathNotFound; error NoMem; error Unseekable; -error Eof; +error EndOfFile; pub const OpenRead = 0b0001; pub const OpenWrite = 0b0010; @@ -153,6 +153,10 @@ pub const OutStream = struct { assert(self.index == 0); os.posixClose(self.fd); } + + pub fn isTty(self: &const OutStream) -> bool { + return os.posix.isatty(self.fd); + } }; // TODO created a BufferedInStream struct and move some of this code there @@ -219,7 +223,7 @@ pub const InStream = struct { pub fn readNoEof(is: &InStream, buf: []u8) -> %void { const amt_read = %return is.read(buf); - if (amt_read < buf.len) return error.Eof; + if (amt_read < buf.len) return error.EndOfFile; } pub fn readByte(is: &InStream) -> %u8 { @@ -228,6 +232,12 @@ pub const InStream = struct { return result[0]; } + pub fn readByteSigned(is: &InStream) -> %i8 { + var result: [1]i8 = undefined; + %return is.readNoEof(([]u8)(result[0...])); + return result[0]; + } + pub fn readIntLe(is: &InStream, comptime T: type) -> %T { is.readInt(false, T) } @@ -342,6 +352,10 @@ pub const InStream = struct { %return buf.resize(actual_buf_len + os.page_size); } } + + pub fn isTty(self: &const InStream) -> bool { + return os.posix.isatty(self.fd); + } }; pub fn openSelfExe() -> %InStream { |
