1 // Copyright (c) 2016 Nuxi, https://nuxi.nl/
3 // SPDX-License-Identifier: BSD-2-Clause
5 #include <common/errno.h>
13 int __wasilibc_nocwd_faccessat(int fd
, const char *path
, int amode
, int flag
) {
14 // Validate function parameters.
15 if ((amode
& ~(F_OK
| R_OK
| W_OK
| X_OK
)) != 0 ||
16 (flag
& ~AT_EACCESS
) != 0) {
21 // Check for target file existence and obtain the file type.
22 __wasi_lookupflags_t lookup_flags
= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW
;
23 __wasi_filestat_t file
;
24 __wasi_errno_t error
=
25 __wasi_path_filestat_get(fd
, lookup_flags
, path
, &file
);
27 errno
= errno_fixup_directory(fd
, error
);
31 // Test whether the requested access rights are present on the
32 // directory file descriptor.
34 __wasi_fdstat_t directory
;
35 error
= __wasi_fd_fdstat_get(fd
, &directory
);
41 __wasi_rights_t min
= 0;
42 if ((amode
& R_OK
) != 0)
43 min
|= file
.filetype
== __WASI_FILETYPE_DIRECTORY
44 ? __WASI_RIGHTS_FD_READDIR
45 : __WASI_RIGHTS_FD_READ
;
46 if ((amode
& W_OK
) != 0)
47 min
|= __WASI_RIGHTS_FD_WRITE
;
49 if ((min
& directory
.fs_rights_inheriting
) != min
) {