sys/mount.h and statfs(2) do not exist on windows

Originally committed to SVN as r5366.
This commit is contained in:
Karl Blomster 2011-02-22 19:03:03 +00:00
parent 387fbdfdea
commit 7db22972a7
3 changed files with 25 additions and 20 deletions

View File

@ -38,8 +38,9 @@ namespace agi {
void str_lower(std::string &str) {
std::locale loc;
for (size_t i=0; i < str.length(); ++i) {
str[i] = std::tolower(str[i]);
str[i] = std::tolower(str[i], loc);
}
}
@ -54,23 +55,5 @@ int strtoi(std::string &str) {
}
uint64_t freespace(std::string &path, PathType type) {
struct statfs fs;
std::string check(path);
if (type == TypeFile)
check.assign(DirName(path));
acs::CheckDirRead(check);
if ((statfs(check.c_str(), &fs)) == 0) {
return fs.f_bsize * fs.f_bavail;
} else {
/// @todo We need a collective set of exceptions for ENOTDIR, EIO etc.
throw("Failed getting free space");
}
}
} // namespace util
} // namespace agi

View File

@ -11,7 +11,6 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/mount.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#else
@ -25,6 +24,11 @@
#include <io.h>
#endif
// Unix C
#ifndef _WIN32
# include <sys/mount.h> // yep, this exists on MacOS X as well, but not on Windows.
#endif
// Common C++
#include <deque>
#include <climits>

View File

@ -59,5 +59,23 @@ void time_log(timeval &tv) {
gettimeofday(&tv, (struct timezone *)NULL);
}
uint64_t freespace(std::string &path, PathType type) {
struct statfs fs;
std::string check(path);
if (type == TypeFile)
check.assign(DirName(path));
acs::CheckDirRead(check);
if ((statfs(check.c_str(), &fs)) == 0) {
return fs.f_bsize * fs.f_bavail;
} else {
/// @todo We need a collective set of exceptions for ENOTDIR, EIO etc.
throw("Failed getting free space");
}
}
} // namespace io
} // namespace agi