From Ken Sewel, added osgDB::fileType(filename) method and usage of this

new function in osgdem to automatcally handle directories as part of the
regular -d and -t options.
This commit is contained in:
Robert Osfield
2004-05-08 06:35:32 +00:00
parent f35cafb778
commit 3d3199017e
3 changed files with 102 additions and 40 deletions

View File

@@ -26,6 +26,8 @@
#define F_OK 4
#else // unix
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include <osg/Notify>
@@ -40,6 +42,40 @@ bool osgDB::fileExists(const std::string& filename)
return access( filename.c_str(), F_OK ) == 0;
}
osgDB::FileType osgDB::fileType(const std::string& filename)
{
#if defined(WIN32) && !defined(__CYGWIN__)
if (!fileExists(const std::string& filename))
{
return FILE_NOT_FOUND;
}
else
{
return REGULAR_FILE;
}
#else
struct stat fileStat;
if(stat(filename.c_str(), &fileStat) == -1)
{
return FILE_NOT_FOUND;
}
if(S_ISREG(fileStat.st_mode))
{
return REGULAR_FILE;
}
if(S_ISDIR(fileStat.st_mode))
{
return DIRECTORY;
}
return FILE_NOT_FOUND;
#endif
}
std::string osgDB::findFileInPath(const std::string& filename, const FilePathList& filepath,CaseSensitivity caseSensitivity)
{
if (filename.empty())