diff options
Diffstat (limited to 'drain.ha')
-rw-r--r-- | drain.ha | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -1,9 +1,20 @@ +use errors; +use fs; use io; use os; use fmt; -fn drain_stdin() []u8 = { - const buf = match (io::drain(os::stdin)) { +fn drain(path: str) []u8 = { + const file = match (os::open(path)) { + case let file: io::file => + yield file; + case errors::noaccess => + fmt::fatalf("error opening {}: access denied", path); + case let err: fs::error => + fmt::fatalf("error opening {}: {}", path, fs::strerror(err)); + }; + defer io::close(file)!; + const buf = match (io::drain(file)) { case let buf: []u8 => yield buf; case let err: io::error => |