mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-18 04:53:06 +01:00
Added stat.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "bx.h"
|
||||
#include "debug.h"
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT
|
||||
# include <windows.h>
|
||||
@@ -274,6 +275,46 @@ namespace bx
|
||||
#endif // BX_COMPILER_
|
||||
}
|
||||
|
||||
struct FileInfo
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
Regular,
|
||||
Directory,
|
||||
|
||||
Count
|
||||
};
|
||||
|
||||
uint64_t m_size;
|
||||
Enum m_type;
|
||||
};
|
||||
|
||||
inline bool stat(const char* _filePath, FileInfo& _fileInfo)
|
||||
{
|
||||
_fileInfo.m_size = 0;
|
||||
_fileInfo.m_type = FileInfo::Count;
|
||||
|
||||
struct stat st;
|
||||
int32_t result = ::stat(_filePath, &st);
|
||||
if (0 != result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (0 != (st.st_mode & S_IFREG) )
|
||||
{
|
||||
_fileInfo.m_type = FileInfo::Regular;
|
||||
}
|
||||
else if (0 != (st.st_mode & S_IFDIR) )
|
||||
{
|
||||
_fileInfo.m_type = FileInfo::Directory;
|
||||
}
|
||||
|
||||
_fileInfo.m_size = st.st_size;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace bx
|
||||
|
||||
#endif // BX_OS_H_HEADER_GUARD
|
||||
|
||||
Reference in New Issue
Block a user