FileSystem: implement IsDirectory in STD implementation

This commit is contained in:
Kawe Mazidjatari 2024-01-13 19:38:06 +01:00
parent dd4fdb6cbd
commit 8eb2561fcf
2 changed files with 19 additions and 1 deletions

View File

@ -6,6 +6,11 @@
//=============================================================================//
#include "filesystem_std.h"
// These are used for the 'stat()' and 'access()' in CBaseFileSystem::IsDirectory().
#include <io.h>
#include <sys/types.h>
#include <sys/stat.h>
ssize_t CBaseFileSystem::Read(void* pOutput, ssize_t size, FileHandle_t file)
{
return fread(pOutput, sizeof(uint8_t), size, (FILE*)file);
@ -331,6 +336,19 @@ int CBaseFileSystem::CreateDirHierarchy(const char* pFileName, const char* pPath
return _mkdir(fullPath);
}
bool CBaseFileSystem::IsDirectory(const char* path, const char* pathID)
{
if (_access(path, 0) == 0)
{
struct stat status;
stat(path, &status);
return (status.st_mode & S_IFDIR) != 0;
}
return false;
}
char* CBaseFileSystem::ReadLine(char* maxChars, ssize_t maxOutputLength, FileHandle_t file)
{
return fgets(maxChars, (int)maxOutputLength, (FILE*)file);

View File

@ -42,7 +42,7 @@ public:
virtual void RemoveFile(char const* pRelativePath, const char* pathID = 0) {}; // Deletes a file (on the WritePath)
virtual bool RenameFile(char const* pOldPath, char const* pNewPath, const char* pathID = 0) { return false; }; // Renames a file (on the WritePath)
virtual int CreateDirHierarchy(const char* path, const char* pathID = 0); // create a local directory structure
virtual bool IsDirectory(const char* pFileName, const char* pathID = 0) { return false; }; // File I/O and info
virtual bool IsDirectory(const char* pFileName, const char* pathID = 0); // File I/O and info
virtual ssize_t FileTimeToString(char* pStrip, ssize_t maxCharsIncludingTerminator, long fileTime) { return NULL; }; // Returns the string size
//--------------------------------------------------------