hare

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

commit d41935e960b36b6e741039e277c88afd2f143d25
parent fb1b551b1e71118e7d8b764642d2e9688fdb0626
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed, 24 Feb 2021 17:12:25 -0500

os: add filesystem convenience functions

Diffstat:
Mos/+linux/dirfdfs.ha | 3---
Mos/fs.ha | 15+++++++++++++++
2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha @@ -67,9 +67,6 @@ export fn dirfdopen(fd: int, resolve: resolve...) *fs::fs = { return fs; }; -// Opens a directory as a filesystem. -export fn diropen(path: fs::path) (*fs::fs | fs::error) = fs::subdir(cwd, path); - // Clones a dirfd filesystem, optionally adding additional [resolve] // constraints. export fn dirfs_clone(fs: *fs::fs, resolve: resolve...) *fs::fs = { diff --git a/os/fs.ha b/os/fs.ha @@ -5,3 +5,18 @@ export let root: *fs::fs = null: *fs::fs; // Provides an implementation of [fs::fs] for the current working directory. export let cwd: *fs::fs = null: *fs::fs; + +// Creates an [fs::iterator] for a given directory to read its contents. +export fn iterdir(path: fs::path) (*fs::iterator | fs::error) = + fs::iter(cwd, path); + +// Reads all entries from a directory. The caller must free the return value +// with [fs::dirents_free]. +export fn readdir(path: fs::path) ([]fs::dirent | fs::error) = + fs::readdir(cwd, path); + +// Returns file information for a given path. +export fn stat(path: fs::path) (fs::filestat | fs::error) = fs::stat(cwd, path); + +// Opens a directory as a filesystem. +export fn diropen(path: fs::path) (*fs::fs | fs::error) = fs::subdir(cwd, path);