hare

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

commit 01fb3245312704f0fad54c55f6edba22fefee509
parent bc606e854fe6944d07a2d7ee49077a8ad917ef1f
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sat, 30 Sep 2023 23:26:21 -0400

glob: add strerror

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mglob/glob.ha | 9+++++++++
1 file changed, 9 insertions(+), 0 deletions(-)

diff --git a/glob/glob.ha b/glob/glob.ha @@ -1,11 +1,13 @@ // SPDX-License-Identifier: MPL-2.0 // (c) Hare authors <https://harelang.org> +use fmt; use fnmatch; use fs; use io; use memio; use os; +use path; use sort; use strings; @@ -53,6 +55,13 @@ export type failure = !struct { error: fs::error, }; +// Converts an error info a human-friendly string. The result is statically +// allocated. +export fn strerror(err: failure) str = { + let buf: [path::MAX + 1024]u8 = [0...]; + return fmt::bsprintf(buf, "{}: {}", err.path, fs::strerror(err.error)); +}; + // Returns a generator of pathnames matching a pattern. The result must be // freed using [[finish]]. export fn glob(pattern: str, flags: flag...) generator = {