hare

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

commit 99f008eb4626172e24889355cfab4a92dbbd234a
parent 4558cf85dc83f3e8d1deffff7dd94cc4822df9da
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sun, 20 Feb 2022 18:46:36 -0500

dirs: add state functions

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

Diffstat:
Mdirs/xdg.ha | 13+++++++++++++
1 file changed, 13 insertions(+), 0 deletions(-)

diff --git a/dirs/xdg.ha b/dirs/xdg.ha @@ -59,3 +59,16 @@ export fn data(prog: str) str = { // Returns an [[fs::fs]] for persistent data files. If "prog" is given, a unique // path for this program to store data will be returned. export fn datafs(prog: str) *fs::fs = os::diropen(data(prog)) as *fs::fs; + +// Returns a directory suitable for storing program state data. The "prog" +// parameter should be a descriptive name unique to this program. The return +// value is statically allocated and will be overwritten on subsequent calls to +// any function in the dirs module. +export fn state(prog: str) str = { + static let buf = path::buffer { ... }; + const fragment = path::set(&buf, ".local", "state")!; + return lookup(prog, "XDG_STATE_HOME", fragment); +}; + +// Returns an [[fs::fs]] for storing program state data. +export fn statefs(prog: str) *fs::fs = os::diropen(state(prog)) as *fs::fs;