hare

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

commit 3d2c96c97d422ef64e2c0de74409cf5a9c3484fe
parent 1294008fa10d63a935e29fbec1330f20302115a3
Author: Mallory Adams <malloryadams@fastmail.com>
Date:   Mon, 29 Jan 2024 18:44:47 -0500

FreeBSD: Use more precise checks in fsflags_to_bsd

The following line would execute successfully on Linux but fail with
`errors::unsupported` on FreeBSD:

```
os::open("/etc", fs::flag::DIRECTORY | fs::flag::RDONLY);
```

That's because `fsflags_to_bsd()` in `os/+freebsd/dirfdfs.ha` contains
the following if block, and `TMPFILE` contains the `DIRECTORY` bit:

```
        if (flags & fs::flag::PATH > 0
                        || flags & fs::flag::NOATIME > 0
                        || flags & fs::flag::TMPFILE > 0) {
                return errors::unsupported;
        };
```

```
export type flag = enum int {
	...
	DIRECTORY	=   0o200000,
	...
	TMPFILE		= 0o20200000,
};
```

Diffstat:
Mos/+freebsd/dirfdfs.ha | 34+++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/os/+freebsd/dirfdfs.ha b/os/+freebsd/dirfdfs.ha @@ -110,51 +110,51 @@ fn _fs_open( fn fsflags_to_bsd(flags: fs::flag) (int | errors::unsupported) = { let out = rt::O_NOCTTY | rt::O_CLOEXEC; - if (flags & fs::flag::WRONLY > 0) { + if (flags & fs::flag::WRONLY == fs::flag::WRONLY) { out |= rt::O_WRONLY; }; - if (flags & fs::flag::RDWR > 0) { + if (flags & fs::flag::RDWR == fs::flag::RDWR) { out |= rt::O_RDWR; }; - if (flags & fs::flag::CREATE > 0) { + if (flags & fs::flag::CREATE == fs::flag::CREATE) { out |= rt::O_CREAT; }; - if (flags & fs::flag::EXCL > 0) { + if (flags & fs::flag::EXCL == fs::flag::EXCL) { out |= rt::O_EXCL; }; - if (flags & fs::flag::CTTY > 0) { + if (flags & fs::flag::CTTY == fs::flag::CTTY) { out &= ~rt::O_NOCTTY; }; - if (flags & fs::flag::TRUNC > 0) { + if (flags & fs::flag::TRUNC == fs::flag::TRUNC) { out |= rt::O_TRUNC; }; - if (flags & fs::flag::APPEND > 0) { + if (flags & fs::flag::APPEND == fs::flag::APPEND) { out |= rt::O_APPEND; }; - if (flags & fs::flag::NONBLOCK > 0) { + if (flags & fs::flag::NONBLOCK == fs::flag::NONBLOCK) { out |= rt::O_NONBLOCK; }; - if (flags & fs::flag::DSYNC > 0) { + if (flags & fs::flag::DSYNC == fs::flag::DSYNC) { out |= rt::O_DSYNC; }; - if (flags & fs::flag::SYNC > 0) { + if (flags & fs::flag::SYNC == fs::flag::SYNC) { out |= rt::O_SYNC; }; - if (flags & fs::flag::RSYNC > 0) { + if (flags & fs::flag::RSYNC == fs::flag::RSYNC) { out |= rt::O_SYNC; }; - if (flags & fs::flag::DIRECTORY > 0) { + if (flags & fs::flag::DIRECTORY == fs::flag::DIRECTORY) { out |= rt::O_DIRECTORY; }; - if (flags & fs::flag::NOFOLLOW > 0) { + if (flags & fs::flag::NOFOLLOW == fs::flag::NOFOLLOW) { out |= rt::O_NOFOLLOW; }; - if (flags & fs::flag::NOCLOEXEC > 0) { + if (flags & fs::flag::NOCLOEXEC == fs::flag::NOCLOEXEC) { out &= ~rt::O_CLOEXEC; }; - if (flags & fs::flag::PATH > 0 - || flags & fs::flag::NOATIME > 0 - || flags & fs::flag::TMPFILE > 0) { + if (flags & fs::flag::PATH == fs::flag::PATH + || flags & fs::flag::NOATIME == fs::flag::NOATIME + || flags & fs::flag::TMPFILE == fs::flag::TMPFILE) { return errors::unsupported; }; return out;