Browse Source

Added stat.

Branimir Karadžić 9 years ago
parent
commit
87ec4ae46b
1 changed files with 41 additions and 0 deletions
  1. 41 0
      include/bx/os.h

+ 41 - 0
include/bx/os.h

@@ -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