hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit ac9b2c35c09d555e09dbd81c5ed95bdfa14313ba
parent 2f8887f661ba204928a530cf8653aff0a4dcc2e1
Author: Alexey Yerin <yyp@disroot.org>
Date:   Sat, 18 Jun 2022 19:31:46 +0300

io: return error from fd_close()

Signed-off-by: Alexey Yerin <yyp@disroot.org>

Diffstat:
Mio/+freebsd/file.ha | 8+++++++-
Mio/+linux/file.ha | 8+++++++-
Mio/handle.ha | 4++--
3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/io/+freebsd/file.ha b/io/+freebsd/file.ha @@ -41,7 +41,13 @@ fn fd_write(fd: file, buf: const []u8) (size | error) = { }; }; -fn fd_close(fd: file) void = rt::close(fd)!; +fn fd_close(fd: file) (void | error) = { + match (rt::close(fd)) { + case void => void; + case let err: rt::errno => + return errors::errno(err); + }; +}; fn fd_seek( fd: file, diff --git a/io/+linux/file.ha b/io/+linux/file.ha @@ -42,7 +42,13 @@ fn fd_write(fd: file, buf: const []u8) (size | error) = { }; }; -fn fd_close(fd: file) void = rt::close(fd)!; +fn fd_close(fd: file) (void | error) = { + match (rt::close(fd)) { + case void => void; + case let err: rt::errno => + return errors::errno(err); + }; +}; fn fd_seek( fd: file, diff --git a/io/handle.ha b/io/handle.ha @@ -40,12 +40,12 @@ export fn write(h: handle, buf: const []u8) (size | error) = { // after calling this function. Closing a file handle can fail only under // certain conditions (for example, closing a file twice, or an interrupted // syscall). However, the user should not attempt to close the file again on -// failure - at best the user should print a diagnostic message and move on. See +// failure - at best the user should print a diagnostic message and move on. See // close(2) for details. export fn close(h: handle) (void | error) = { match (h) { case let fd: file => - fd_close(fd); + fd_close(fd)?; case let st: *stream => st_close(st)?; };