move msghdr and cmsghdr out of bits/socket.h
[musl.git] / src / stat / statvfs.c
blobf65d1b548d41eae429223ddca818b3a71ba8d6b7
1 #include <sys/statvfs.h>
2 #include <sys/statfs.h>
3 #include "syscall.h"
5 static int __statfs(const char *path, struct statfs *buf)
7 *buf = (struct statfs){0};
8 #ifdef SYS_statfs64
9 return syscall(SYS_statfs64, path, sizeof *buf, buf);
10 #else
11 return syscall(SYS_statfs, path, buf);
12 #endif
15 static int __fstatfs(int fd, struct statfs *buf)
17 *buf = (struct statfs){0};
18 #ifdef SYS_fstatfs64
19 return syscall(SYS_fstatfs64, fd, sizeof *buf, buf);
20 #else
21 return syscall(SYS_fstatfs, fd, buf);
22 #endif
25 weak_alias(__statfs, statfs);
26 weak_alias(__fstatfs, fstatfs);
28 static void fixup(struct statvfs *out, const struct statfs *in)
30 *out = (struct statvfs){0};
31 out->f_bsize = in->f_bsize;
32 out->f_frsize = in->f_frsize ? in->f_frsize : in->f_bsize;
33 out->f_blocks = in->f_blocks;
34 out->f_bfree = in->f_bfree;
35 out->f_bavail = in->f_bavail;
36 out->f_files = in->f_files;
37 out->f_ffree = in->f_ffree;
38 out->f_favail = in->f_ffree;
39 out->f_fsid = in->f_fsid.__val[0];
40 out->f_flag = in->f_flags;
41 out->f_namemax = in->f_namelen;
44 int statvfs(const char *restrict path, struct statvfs *restrict buf)
46 struct statfs kbuf;
47 if (__statfs(path, &kbuf)<0) return -1;
48 fixup(buf, &kbuf);
49 return 0;
52 int fstatvfs(int fd, struct statvfs *buf)
54 struct statfs kbuf;
55 if (__fstatfs(fd, &kbuf)<0) return -1;
56 fixup(buf, &kbuf);
57 return 0;
60 weak_alias(statvfs, statvfs64);
61 weak_alias(statfs, statfs64);
62 weak_alias(fstatvfs, fstatvfs64);
63 weak_alias(fstatfs, fstatfs64);