Daniele Bartolini 2 лет назад
Родитель
Сommit
4bd5038c6d
2 измененных файлов с 15 добавлено и 1 удалено
  1. 12 1
      src/core/os.cpp
  2. 3 0
      src/core/os.h

+ 12 - 1
src/core/os.cpp

@@ -29,7 +29,7 @@
 	#include <string.h>   // memset
 	#include <sys/wait.h> // wait
 	#include <time.h>     // clock_gettime
-	#include <unistd.h>   // unlink, rmdir, getcwd, access
+	#include <unistd.h>   // unlink, rmdir, getcwd, access, chdir
 #endif // if CROWN_PLATFORM_WINDOWS
 #if CROWN_PLATFORM_ANDROID
 	#include <android/log.h>
@@ -232,6 +232,17 @@ namespace os
 #endif
 	}
 
+	void setcwd(const char *cwd)
+	{
+#if CROWN_PLATFORM_WINDOWS
+		BOOL ret = SetCurrentDirectory(cwd);
+		CE_UNUSED(ret);
+#else
+		int ret = chdir(cwd);
+		CE_UNUSED(ret);
+#endif
+	}
+
 	const char *getenv(const char *name)
 	{
 #if CROWN_PLATFORM_WINDOWS

+ 3 - 0
src/core/os.h

@@ -113,6 +113,9 @@ namespace os
 	/// Returns the current working directory.
 	const char *getcwd(char *buf, u32 size);
 
+	/// Sets the current working directory.
+	void setcwd(const char *cwd);
+
 	/// Returns the value of the environment variable @a name.
 	const char *getenv(const char *name);