diff --git a/include/bx/os.h b/include/bx/os.h index db91139..def60c6 100644 --- a/include/bx/os.h +++ b/include/bx/os.h @@ -8,6 +8,7 @@ #include "bx.h" #include "debug.h" +#include #if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT # include @@ -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