nvidia-texture-tools/src/nvcore/FileSystem.cpp

48 lines
955 B
C++
Raw Normal View History

2008-11-22 22:07:07 +00:00
// This code is in the public domain -- castano@gmail.com
#include "FileSystem.h"
#include <nvcore/nvcore.h>
#if NV_OS_WIN32
//#include <shlwapi.h> // PathFileExists
#include <windows.h> // GetFileAttributes
#include <direct.h> // _mkdir
2008-11-22 22:07:07 +00:00
#else
#include <sys/stat.h>
#include <sys/types.h>
2009-01-09 02:24:32 +00:00
#include <unistd.h>
2008-11-22 22:07:07 +00:00
#endif
using namespace nv;
bool FileSystem::exists(const char * path)
{
2009-01-09 02:24:32 +00:00
#if NV_OS_UNIX
return access(path, F_OK|R_OK) == 0;
//struct stat buf;
//return stat(path, &buf) == 0;
#elif NV_OS_WIN32
// PathFileExists requires linking to shlwapi.lib
//return PathFileExists(path) != 0;
return GetFileAttributes(path) != 0xFFFFFFFF;
2009-01-09 02:24:32 +00:00
#else
if (FILE * fp = fopen(path, "r"))
{
fclose(fp);
return true;
}
return false;
#endif
2008-11-22 22:07:07 +00:00
}
bool FileSystem::createDirectory(const char * path)
{
#if NV_OS_WIN32
return _mkdir(path) != -1;
#else
return mkdir(path, 0777) != -1;
#endif
}
2009-01-09 02:24:32 +00:00