Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Unified Diff: fusl/src/stat/statvfs.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/stat/stat.c ('k') | fusl/src/stat/umask.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/stat/statvfs.c
diff --git a/fusl/src/stat/statvfs.c b/fusl/src/stat/statvfs.c
new file mode 100644
index 0000000000000000000000000000000000000000..30d587971b0a0946ae4293dc43cb54d231d763fd
--- /dev/null
+++ b/fusl/src/stat/statvfs.c
@@ -0,0 +1,64 @@
+#include <sys/statvfs.h>
+#include <sys/statfs.h>
+#include "syscall.h"
+#include "libc.h"
+
+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
+}
+
+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;
+}
+
+LFS64(statvfs);
+LFS64(statfs);
+LFS64(fstatvfs);
+LFS64(fstatfs);
« no previous file with comments | « fusl/src/stat/stat.c ('k') | fusl/src/stat/umask.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698