hare

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

commit cee7bd005cdcdc0da162b8b9cde1b5d34d83217e
parent 43375866f18b7576e3368039af7edaa7617f0e13
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  9 Mar 2021 14:49:34 -0500

fs: use fs::mode for create

Diffstat:
Mfs/fs.ha | 15+++++++++------
Mfs/types.ha | 2+-
Mos/+linux/dirfdfs.ha | 2+-
Mos/+linux/open.ha | 9++++++---
4 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/fs/fs.ha b/fs/fs.ha @@ -9,9 +9,8 @@ export fn close(fs: *fs) void = { }; }; -// Opens a file. -// -// If no flags are provided, the default read/write mode is RDONLY. +// Opens a file. If no flags are provided, the default read/write mode is +// RDONLY. export fn open( fs: *fs, path: path::path, @@ -23,14 +22,18 @@ export fn open( }; }; -// Equivalent to [open], but allows the caller to specify a file mode for the -// new file. If no other flag is given, the default read/write mode is WRONLY. +// Creates a new file and opens it for writing. If no flags are provided, the +// default read/write mode is WRONLY. +// +// Only the permission bits of the mode are used. If other bits are set, they +// are discarded. export fn create( fs: *fs, path: path::path, - mode: uint, + mode: mode, flags: flags... ) (*io::stream | error) = { + mode = mode & 0o777; return match (fs.create) { null => io::unsupported, f: *createfunc => f(fs, path, mode, flags...), diff --git a/fs/types.ha b/fs/types.ha @@ -176,7 +176,7 @@ export type openfunc = fn( export type createfunc = fn( fs: *fs, path: path::path, - mode: uint, + mode: mode, flags: flags... ) (*io::stream | error); diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha @@ -157,7 +157,7 @@ fn fs_open( fn fs_create( fs: *fs::fs, path: path::path, - mode: uint, + mode: fs::mode, flags: fs::flags... ) (*io::stream | fs::error) = { let oflags = 0; diff --git a/os/+linux/open.ha b/os/+linux/open.ha @@ -2,7 +2,7 @@ use fs; use io; use path; -// Opens a file from the filesystem. +// Opens a file. // // If no flags are provided, [fs::flags::RDONLY], [fs::flags::NOCTTY], // [fs::flags::CLOEXEC] are used when opening the file. If you pass your own @@ -13,14 +13,17 @@ export fn open( flags: fs::flags... ) (*io::stream | fs::error) = fs::open(cwd, path, flags...); -// Opens a file from the filesystem. +// Creates a new file and opens it for writing. // // If no flags are provided, [fs::flags::WRONLY], [fs::flags::NOCTTY], // [fs::flags::CLOEXEC] are used when opening the file. If you pass your own // flags, it is recommended that you add the latter two unless you know that you // do not want them. +// +// Only the permission bits of the mode are used. If other bits are set, they +// are discarded. export fn create( path: path::path, - mode: uint, + mode: fs::mode, flags: fs::flags... ) (*io::stream | fs::error) = fs::create(cwd, path, mode, flags...);