]> git.proxmox.com Git - wasi-libc.git/blame - libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c
Remove __wasilibc_unmodified_upstream markers from libc-bottom-half.
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / sys / stat / fstatat.c
CommitLineData
320054e8
DG
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
446cb3f1 9#include <wasi/api.h>
320054e8
DG
10#include <errno.h>
11#include <fcntl.h>
12#include <string.h>
13
14#include "stat_impl.h"
15
16int fstatat(int fd, const char *restrict path, struct stat *restrict buf,
17 int flag) {
18 // Create lookup properties.
320054e8 19 __wasi_lookupflags_t lookup_flags = 0;
320054e8 20 if ((flag & AT_SYMLINK_NOFOLLOW) == 0)
446cb3f1 21 lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW;
320054e8
DG
22
23 // Perform system call.
24 __wasi_filestat_t internal_stat;
25 __wasi_errno_t error =
320054e8 26 __wasi_path_filestat_get(fd, lookup_flags, path, strlen(path), &internal_stat);
320054e8
DG
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}