소스 검색

core: add os::access()

Daniele Bartolini 6 년 전
부모
커밋
78dc13fd7c
2개의 변경된 파일29개의 추가작업 그리고 2개의 파일을 삭제
  1. 12 2
      src/core/os.cpp
  2. 17 0
      src/core/os.h

+ 12 - 2
src/core/os.cpp

@@ -22,9 +22,9 @@
 	#include <string.h>   // memset
 	#include <sys/wait.h> // wait
 	#include <time.h>     // clock_gettime
-	#include <unistd.h>   // unlink, rmdir, getcwd, fork, execv
+	#include <unistd.h>   // unlink, rmdir, getcwd, fork, execv, access
 #elif CROWN_PLATFORM_WINDOWS
-	#include <io.h>
+	#include <io.h>       // _access
 	#include <stdio.h>
 	#include <windows.h>
 #endif
@@ -228,6 +228,16 @@ namespace os
 #endif
 	}
 
+	///
+	s32 access(const char* path, u32 flags)
+	{
+#if CROWN_PLATFORM_POSIX
+		return ::access(path, flags);
+#elif CROWN_PLATFORM_WINDOWS
+		return ::_access(path, flags);
+#endif
+	}
+
 	int execute_process(const char* const* argv, StringStream& output)
 	{
 		TempAllocator512 ta;

+ 17 - 0
src/core/os.h

@@ -28,6 +28,20 @@ struct Stat
 	u64 mtime; ///< Last modified time.
 };
 
+/// File access flags to be used with os::access().
+///
+/// @ingroup OS
+struct AccessFlags
+{
+	enum Enum
+	{
+		EXISTS  = 0x0,
+		EXECUTE = 0x1,
+		WRITE   = 0x2,
+		READ    = 0x4
+	};
+};
+
 /// Operating system functions.
 ///
 /// @ingroup OS
@@ -69,6 +83,9 @@ namespace os
 	/// Returns the value of the environment variable @a name.
 	const char* getenv(const char* name);
 
+	///
+	s32 access(const char* path, u32 flags);
+
 	/// Executes the process described by @a argv and returns its exit code.
 	/// It fills @a output with stdout and stderr.
 	int execute_process(const char* const* argv, StringStream& output);