anoia.fs: improve error messages

This commit is contained in:
Daniel Barlow 2024-08-08 11:36:47 +01:00
parent 64afd18e2a
commit 0a629df48d
1 changed files with 8 additions and 2 deletions

View File

@ -9,6 +9,12 @@
(local S_IFCHR 0x2000)
(local S_IFIFO 0x1000)
(macro errno-check [x]
`(match ,x
val# val#
(nil errno#) (assert nil (.. "system call failed, errno=" errno#))
))
(fn ifmt-bits [mode] (and mode (band mode 0xf000)))
(fn file-type [pathname]
@ -33,10 +39,10 @@
(or (directory? pathname)
(let [parent (string.gsub pathname "/[^/]+/?$" "")]
(or (directory? parent) (mktree parent))
(assert (ll.mkdir pathname)))))
(errno-check (ll.mkdir pathname)))))
(fn dir [name]
(let [dp (assert (ll.opendir name) name)]
(let [dp (errno-check (ll.opendir name) name)]
(fn []
(case (ll.readdir dp)
(name filetype) (values name filetype)