Skip to content

CMake (Hurd): Define O_PATH to O_NORW. - #2498

Merged
CarterLi merged 1 commit into
fastfetch-cli:devfrom
yelninei:O_NORW
Aug 7, 2026
Merged

CMake (Hurd): Define O_PATH to O_NORW.#2498
CarterLi merged 1 commit into
fastfetch-cli:devfrom
yelninei:O_NORW

Conversation

@yelninei

@yelninei yelninei commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

This is a noop because O_RW is 0 but O_NORW is the correct constant to open a file without read/write permissions.

This is a noop because O_RW is 0 but O_NORW is the correct constant to
open a file without read/write permissions.
@CarterLi

CarterLi commented Aug 7, 2026

Copy link
Copy Markdown
Member

Do you mean O_NORW is 0?

@yelninei

yelninei commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Yes, but inlike 0 which I put there initially to make the missing O_PATH be ignored it is defined to roughly the same as O_PATH (and because read/write permissions are a bitmask on Hurd 0 is accidentally the right flag for that)

/* In GNU, read and write are bits (unlike BSD).  */
#ifdef __USE_GNU
# define O_READ		O_RDONLY /* Open for reading.  */
# define O_WRITE	O_WRONLY /* Open for writing.  */
# define O_EXEC		0x0004	/* Open for execution.  */
# define O_NORW		0	/* Open without R/W access.  */
#endif
/* POSIX.1 standard names.  */
#define	O_RDONLY	0x0001	/* Open read-only.  */
#define	O_WRONLY	0x0002	/* Open write-only.  */
#define	O_RDWR		(O_RDONLY|O_WRONLY) /* Open for reading and writing. */
#define	O_ACCMODE	O_RDWR	/* Mask for file access modes.  */

I found out about O_NORW while browsing the debian package fir procps https://salsa.debian.org/debian/procps/-/blob/master/debian/patches/no-opath

@CarterLi

CarterLi commented Aug 7, 2026

Copy link
Copy Markdown
Member

0 is accidentally the right flag for that

It's not accidentally. | 0 is a noop. 0 must be no read/write as long as you don't write 0 | O_RDONLY or 0 | O_WRONLY.

I still prefer 0 because O_NORW is not standard and I never saw it before.

@yelninei

yelninei commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

I still prefer 0 because O_NORW is not standard

Neither is O_PATH which is linux specific (it seems to also exists in the recent freebsd versions for linux compatibilty)

0 must be no read/write

That is wrong in general but true on Hurd where O_RDWR = (O_RDONLY|O_WRONLY).

On linux O_RDONLY is 0 so in the general open flags of 0 are not no r/w.

https://sourceware.org/glibc/manual/latest/html_node/Access-Modes.html

Macro: int O_PATH

    Obtain a file descriptor for the file, but do not open the file for reading or writing. Permission checks for the file itself are skipped when the file is opened (but permission to access the directory that contains it is still needed), and permissions are checked when the descriptor is used later on.

    For example, such descriptors can be used with the fexecve function (see Executing a File). Other applications involve the ‘*at’ function variants, along with the AT_EMPTY_PATH flag. See Descriptor-Relative Access.

    This access mode is specific to Linux. On GNU/Hurd systems, it is possible to use O_EXEC explicitly, or specify no access modes at all (see below). 

I put it there to make x | O_PATH a noop to ignore that O_PATH is not defined. But (accidentaly) by the way the openflags are implemented this is also how O_NORW works but with a guaranteed permisson semantic instead.

@CarterLi
CarterLi merged commit 8686820 into fastfetch-cli:dev Aug 7, 2026
24 checks passed
@yelninei
yelninei deleted the O_NORW branch August 7, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants