diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 13:54:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 13:54:38 +0000 |
commit | 8c1ab65c0f548d20b7f177bdb736daaf603340e1 (patch) | |
tree | df55b7e75bf43f2bf500845b105afe3ac3a5157e /libc-top-half/musl/src/stat/statvfs.c | |
parent | Initial commit. (diff) | |
download | wasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.tar.xz wasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.zip |
Adding upstream version 0.0~git20221206.8b7148f.upstream/0.0_git20221206.8b7148f
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-top-half/musl/src/stat/statvfs.c')
-rw-r--r-- | libc-top-half/musl/src/stat/statvfs.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/stat/statvfs.c b/libc-top-half/musl/src/stat/statvfs.c new file mode 100644 index 0000000..f65d1b5 --- /dev/null +++ b/libc-top-half/musl/src/stat/statvfs.c @@ -0,0 +1,63 @@ +#include <sys/statvfs.h> +#include <sys/statfs.h> +#include "syscall.h" + +static int __statfs(const char *path, struct statfs *buf) +{ + *buf = (struct statfs){0}; +#ifdef SYS_statfs64 + return syscall(SYS_statfs64, path, sizeof *buf, buf); +#else + return syscall(SYS_statfs, path, buf); +#endif +} + +static int __fstatfs(int fd, struct statfs *buf) +{ + *buf = (struct statfs){0}; +#ifdef SYS_fstatfs64 + return syscall(SYS_fstatfs64, fd, sizeof *buf, buf); +#else + return syscall(SYS_fstatfs, fd, buf); +#endif +} + +weak_alias(__statfs, statfs); +weak_alias(__fstatfs, fstatfs); + +static void fixup(struct statvfs *out, const struct statfs *in) +{ + *out = (struct statvfs){0}; + out->f_bsize = in->f_bsize; + out->f_frsize = in->f_frsize ? in->f_frsize : in->f_bsize; + out->f_blocks = in->f_blocks; + out->f_bfree = in->f_bfree; + out->f_bavail = in->f_bavail; + out->f_files = in->f_files; + out->f_ffree = in->f_ffree; + out->f_favail = in->f_ffree; + out->f_fsid = in->f_fsid.__val[0]; + out->f_flag = in->f_flags; + out->f_namemax = in->f_namelen; +} + +int statvfs(const char *restrict path, struct statvfs *restrict buf) +{ + struct statfs kbuf; + if (__statfs(path, &kbuf)<0) return -1; + fixup(buf, &kbuf); + return 0; +} + +int fstatvfs(int fd, struct statvfs *buf) +{ + struct statfs kbuf; + if (__fstatfs(fd, &kbuf)<0) return -1; + fixup(buf, &kbuf); + return 0; +} + +weak_alias(statvfs, statvfs64); +weak_alias(statfs, statfs64); +weak_alias(fstatvfs, fstatvfs64); +weak_alias(fstatfs, fstatfs64); |