|
|
|
@ -49,12 +49,14 @@ SOFTWARE.
|
|
|
|
|
|
|
|
|
|
#include "modules/Filesystem.h"
|
|
|
|
|
|
|
|
|
|
bool DFHack::Filesystem::chdir (std::string path)
|
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
|
|
bool Filesystem::chdir (std::string path)
|
|
|
|
|
{
|
|
|
|
|
return !(bool)::chdir(path.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string DFHack::Filesystem::getcwd ()
|
|
|
|
|
std::string Filesystem::getcwd ()
|
|
|
|
|
{
|
|
|
|
|
char *path;
|
|
|
|
|
char buf[FILENAME_MAX];
|
|
|
|
@ -68,7 +70,7 @@ std::string DFHack::Filesystem::getcwd ()
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DFHack::Filesystem::mkdir (std::string path)
|
|
|
|
|
bool Filesystem::mkdir (std::string path)
|
|
|
|
|
{
|
|
|
|
|
int fail;
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
@ -80,7 +82,7 @@ bool DFHack::Filesystem::mkdir (std::string path)
|
|
|
|
|
return !(bool)fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DFHack::Filesystem::rmdir (std::string path)
|
|
|
|
|
bool Filesystem::rmdir (std::string path)
|
|
|
|
|
{
|
|
|
|
|
int fail;
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
@ -114,31 +116,45 @@ _filetype mode2type (mode_t mode) {
|
|
|
|
|
return FILETYPE_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DFHack::Filesystem::stat (std::string path, STAT_STRUCT &info)
|
|
|
|
|
bool Filesystem::stat (std::string path, STAT_STRUCT &info)
|
|
|
|
|
{
|
|
|
|
|
return !(bool)(STAT_FUNC(path.c_str(), &info));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DFHack::Filesystem::exists (std::string path)
|
|
|
|
|
bool Filesystem::exists (std::string path)
|
|
|
|
|
{
|
|
|
|
|
STAT_STRUCT info;
|
|
|
|
|
return (bool)DFHack::Filesystem::stat(path.c_str(), info);
|
|
|
|
|
return (bool)Filesystem::stat(path.c_str(), info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
_filetype DFHack::Filesystem::filetype (std::string path)
|
|
|
|
|
_filetype Filesystem::filetype (std::string path)
|
|
|
|
|
{
|
|
|
|
|
STAT_STRUCT info;
|
|
|
|
|
DFHack::Filesystem::stat(path, info);
|
|
|
|
|
Filesystem::stat(path, info);
|
|
|
|
|
return mode2type(info.st_mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DFHack::Filesystem::isfile (std::string path)
|
|
|
|
|
bool Filesystem::isfile (std::string path)
|
|
|
|
|
{
|
|
|
|
|
return DFHack::Filesystem::filetype(path) == FILETYPE_FILE;
|
|
|
|
|
return Filesystem::filetype(path) == FILETYPE_FILE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DFHack::Filesystem::isdir (std::string path)
|
|
|
|
|
bool Filesystem::isdir (std::string path)
|
|
|
|
|
{
|
|
|
|
|
return DFHack::Filesystem::filetype(path) == FILETYPE_DIRECTORY;
|
|
|
|
|
return Filesystem::filetype(path) == FILETYPE_DIRECTORY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define DEFINE_STAT_TIME_WRAPPER(attr) \
|
|
|
|
|
int64_t Filesystem::attr (std::string path) \
|
|
|
|
|
{ \
|
|
|
|
|
STAT_STRUCT info; \
|
|
|
|
|
if (!Filesystem::stat(path.c_str(), info)) \
|
|
|
|
|
return -1; \
|
|
|
|
|
return (int64_t)info.st_##attr; \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEFINE_STAT_TIME_WRAPPER(atime);
|
|
|
|
|
DEFINE_STAT_TIME_WRAPPER(ctime);
|
|
|
|
|
DEFINE_STAT_TIME_WRAPPER(mtime);
|
|
|
|
|
|
|
|
|
|
#undef DEFINE_STAT_TIME_WRAPPER
|
|
|
|
|