| /* A part of the Windows CE C Extra Library (celibc) |
| Copyright 2007-2015 PC GO Ld. |
| |
| This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| */ |
| |
| #include <sys/statfs.h> |
| #include <windows.h> |
| #include <errno.h> |
| |
| int statfs(const char *path, struct statfs *buffer) { |
| if(!path || !buffer) { |
| errno = EFAULT; |
| return -1; |
| } |
| |
| ULARGE_INTEGER available, total; |
| size_t len = strlen(path) + 1; |
| wchar_t wpath[len]; |
| if((int)mbstowcs(wpath, path, len) < 0) return -1; |
| if(!GetDiskFreeSpaceExW(wpath, &available, &total, NULL)) return -1; |
| |
| buffer->f_bsize = 512; // XXX |
| buffer->f_blocks = total.QuadPart / buffer->f_bsize; |
| buffer->f_bfree = available.QuadPart / buffer->f_bsize; |
| return 0; |
| } |