]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c
WASI libc prototype implementation.
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / sys / stat / fstat.c
1 // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
2 //
3 // SPDX-License-Identifier: BSD-2-Clause
4
5 #include <sys/stat.h>
6
7 #include <wasi/core.h>
8 #include <errno.h>
9
10 #include "stat_impl.h"
11
12 int fstat(int fildes, struct stat *buf) {
13 __wasi_filestat_t internal_stat;
14 #ifdef __wasilibc_unmodified_upstream // fstat
15 __wasi_errno_t error = __wasi_file_stat_fget(fildes, &internal_stat);
16 #else
17 __wasi_errno_t error = __wasi_fd_filestat_get(fildes, &internal_stat);
18 #endif
19 if (error != 0) {
20 errno = error;
21 return -1;
22 }
23 to_public_stat(&internal_stat, buf);
24 return 0;
25 }