commit ee411a91e24bf048158f117c01e9e7f506347183
parent bacd8ac31527b2cc0c7f268b5da0d40fb4d1a6ea
Author: Sebastian <sebastian@sebsite.pw>
Date: Tue, 26 Apr 2022 18:13:40 -0400
io::close can error
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
5 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/cat.ha b/cat.ha
@@ -18,8 +18,13 @@ export fn utilmain() (main::error | void) = {
for (let i = 0z; i < len(cmd.args); i += 1z) {
const file = open(cmd.args[i]);
- defer io::close(file);
- io::copy(os::stdout, file)?;
+ match (io::copy(os::stdout, file)) {
+ case size => void;
+ case let err: io::error =>
+ io::close(file): void;
+ return err;
+ };
+ io::close(file)?;
};
};
diff --git a/head.ha b/head.ha
@@ -37,10 +37,15 @@ export fn utilmain() (void | main::error) = {
case let file: io::file =>
yield file;
};
- defer io::close(file);
static let buf: [os::BUFSIZ]u8 = [0...];
const file = bufio::buffered(file, buf, []);
- head(&file, n)?;
+ match (head(&file, n)) {
+ case void => void;
+ case let err: main::error =>
+ io::close(file.source): void;
+ return err;
+ };
+ io::close(file.source)?;
};
};
diff --git a/nl.ha b/nl.ha
@@ -182,7 +182,7 @@ export fn utilmain() (void | main::error) = {
else
os::stdin;
- defer io::close(input);
+ defer io::close(input)!;
static const delim_head_buf: [2 * 3]u8 = [0...];
static const delim_body_buf: [2 * 2]u8 = [0...];
diff --git a/tee.ha b/tee.ha
@@ -31,7 +31,7 @@ export fn utilmain() (main::error | void) = {
let files: []io::file = [];
defer {
for (let i = 0z; i < len(files); i += 1) {
- io::close(files[i]);
+ io::close(files[i])!;
};
free(files);
};
diff --git a/wc.ha b/wc.ha
@@ -69,7 +69,7 @@ export fn utilmain() (main::error | void) = {
for (let i = 0z; i < len(cmd.args); i += 1) {
// TODO: Mention which file failed on error
const in = os::open(cmd.args[i])?;
- defer io::close(in);
+ defer io::close(in)!;
const result = count(in, mode)?;
print(mode, &result, cmd.args[i])?;
totals.bytes += result.bytes;