Polyfill statfs() and fstatfs() on Windows

This commit is contained in:
Justine Tunney 2022-08-17 18:57:03 -07:00
parent f7ee9d7d99
commit c2211c9e63
16 changed files with 370 additions and 50 deletions

View file

@ -17,10 +17,13 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/strace.internal.h"
#include "libc/calls/struct/statfs-meta.internal.h"
#include "libc/calls/struct/statfs.internal.h"
#include "libc/dce.h"
#include "libc/runtime/stack.h"
#include "libc/sysv/errfuns.h"
/**
* Returns information about filesystem.
@ -29,8 +32,14 @@ int fstatfs(int fd, struct statfs *sf) {
int rc;
union statfs_meta m;
CheckLargeStackAllocation(&m, sizeof(m));
if ((rc = sys_fstatfs(fd, &m)) != -1) {
statfs2cosmo(sf, &m);
if (!IsWindows()) {
if ((rc = sys_fstatfs(fd, &m)) != -1) {
statfs2cosmo(sf, &m);
}
} else if (__isfdopen(fd)) {
rc = sys_fstatfs_nt(g_fds.p[fd].handle, sf);
} else {
rc = ebadf();
}
STRACE("fstatfs(%d, [%s]) → %d% m", fd, DescribeStatfs(rc, sf));
return rc;