| /* A part of the Native C Library for Windows NT |
| Copyright 2015-2016 Rivoreo |
| |
| 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 <string.h> |
| #include <unistd.h> |
| #include <fcntl.h> |
| #include <errno.h> |
| |
| int fstatfs(int fd, struct statfs *buffer) { |
| if(!buffer) { |
| errno = EFAULT; |
| return -1; |
| } |
| |
| struct statvfs st; |
| if(fstatvfs(fd, &st) < 0) return -1; |
| buffer->f_bsize = st.f_frsize; |
| buffer->f_blocks = st.f_blocks; |
| buffer->f_bfree = st.f_bfree; |
| buffer->f_bavail = st.f_bavail; |
| strncpy(buffer->f_mntfromname, st.f_mntfromname, MNAMELEN); |
| |
| return 0; |
| } |
| |
| int statfs(const char *path, struct statfs *buffer) { |
| if(!path || !buffer) { |
| errno = EFAULT; |
| return -1; |
| } |
| if(!*path) { |
| errno = ENOENT; |
| return -1; |
| } |
| |
| int fd = open(path, O_RDONLY); |
| if(fd == -1) return -1; |
| |
| int r = fstatfs(fd, buffer); |
| int e = errno; |
| close(fd); |
| errno = e; |
| return r; |
| } |