]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c
Update README and add CI-tests for minimal supported LLVM-version (10) (#302)
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / sys / stat / fstatat.c
1 // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
2 //
3 // SPDX-License-Identifier: BSD-2-Clause
4
5 #include <common/errno.h>
6
7 #include <sys/stat.h>
8
9 #include <wasi/api.h>
10 #include <errno.h>
11 #include <fcntl.h>
12 #include <string.h>
13
14 #include "stat_impl.h"
15
16 int __wasilibc_nocwd_fstatat(int fd, const char *restrict path, struct stat *restrict buf,
17 int flag) {
18 // Create lookup properties.
19 __wasi_lookupflags_t lookup_flags = 0;
20 if ((flag & AT_SYMLINK_NOFOLLOW) == 0)
21 lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW;
22
23 // Perform system call.
24 __wasi_filestat_t internal_stat;
25 __wasi_errno_t error =
26 __wasi_path_filestat_get(fd, lookup_flags, path, &internal_stat);
27 if (error != 0) {
28 errno = errno_fixup_directory(fd, error);
29 return -1;
30 }
31 to_public_stat(&internal_stat, buf);
32 return 0;
33 }