summaryrefslogtreecommitdiff
path: root/drain.ha
diff options
context:
space:
mode:
Diffstat (limited to 'drain.ha')
-rw-r--r--drain.ha15
1 files changed, 13 insertions, 2 deletions
diff --git a/drain.ha b/drain.ha
index d270108..a76184b 100644
--- a/drain.ha
+++ b/drain.ha
@@ -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 =>