hare

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

commit 4b68264ddce335f0d43f29c77219a5dad718eb3e
parent 9add014b286118bd2e0a0b9c0e9e1c1e9aa095ce
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed, 24 Feb 2021 11:53:31 -0500

fs::filestat: use path type

Diffstat:
Mfs/types.ha | 21+++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/fs/types.ha b/fs/types.ha @@ -90,12 +90,11 @@ export type stat_mask = enum uint { // Information about a file or directory. The mask field defines what other // fields are set; mode and path are always set. // -// The path string is typically borrowed from the filesystem's internal state; -// if you want to keep this around for any length of time you should use -// [stat_dup]. +// The path string may be borrowed from the filesystem's internal state; if you +// want to keep this around for any length of time you should use [stat_dup]. export type filestat = struct { mask: stat_mask, - path: str, + path: path, mode: mode, uid: uint, gid: uint, @@ -106,12 +105,22 @@ export type filestat = struct { // Duplicates a [filestat] object. Call [stat_free] to get rid of it later. export fn stat_dup(f: filestat) filestat = { let new = f; - new.path = strings::dup(new.path); + new.path = match (new.path) { + s: str => strings::dup(s), + b: []u8 => { + let n: []u8 = []; + append(n, ...b); + n; + }, + }; return new; }; // Frees a [filestat] object which was duplicated with [stat_dup]. -export fn stat_free(f: filestat) void = free(f.path); +export fn stat_free(f: filestat) void = match (f.path) { + s: str => free(s), + b: []u8 => free(b), +}; export type closefunc = fn(fs: *fs) void; export type openfunc = fn(fs: *fs, path: path, mode: io::mode) (*io::stream | error);