The O_DIRECTORY option signifies that an open call should only succeed if the path is a directory.
This is used, for example, by opendir in the musl library:
Some programs use opendir to determine if a path is a directory and so it is important to support.
The following is a test program which must be named opendir.c and run in the same directory as the source. However, any path to an existing file can be used to test whether O_DIRECTORY is working.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main() {
int dirfd = open("opendir.c", O_DIRECTORY);
printf("dirfd is %d\n", dirfd);
}
If O_DIRECTORY is working, then the path will not open and dirfd will be -1.
A PR is forthcoming that implements O_DIRECTORY in Fiwix.
The O_DIRECTORY option signifies that an open call should only succeed if the path is a directory. This is used, for example, by opendir in the musl library:
https://git.musl-libc.org/cgit/musl/tree/src/dirent/opendir.c
Some programs use opendir to determine if a path is a directory and so it is important to support.
The following is a test program which must be named opendir.c and run in the same directory as the source. However, any path to an existing file can be used to test whether O_DIRECTORY is working.
If O_DIRECTORY is working, then the path will not open and dirfd will be -1.
A PR is forthcoming that implements O_DIRECTORY in Fiwix.