Преглед на файлове

added os_mkdir to platform functions

jp9000 преди 12 години
родител
ревизия
fcf7e508a9
променени са 3 файла, в които са добавени 37 реда и са изтрити 0 реда
  1. 12 0
      libobs/util/platform-nix.c
  2. 19 0
      libobs/util/platform-windows.c
  3. 6 0
      libobs/util/platform.h

+ 12 - 0
libobs/util/platform-nix.c

@@ -21,6 +21,9 @@
      distribution.
 ******************************************************************************/
 
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <stdlib.h>
 
 #include "dstr.h"
@@ -71,3 +74,12 @@ char *os_get_home_path(void)
 	/* TODO */
 	return NULL;
 }
+
+int os_mkdir(const char *path)
+{
+	int errorcode = mkdir(path, S_IRWXU);
+	if (errorcode == 0)
+		return MKDIR_SUCCESS;
+
+	return (errno == EEXIST) ? MKDIR_EXISTS : MKDIR_ERROR;
+}

+ 19 - 0
libobs/util/platform-windows.c

@@ -153,6 +153,7 @@ char *os_get_home_path(void)
 {
 	char *out;
 	wchar_t path_utf16[MAX_PATH];
+
 	SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
 			path_utf16);
 
@@ -160,6 +161,24 @@ char *os_get_home_path(void)
 	return out;
 }
 
+int os_mkdir(const char *path)
+{
+	wchar_t *path_utf16;
+	BOOL success;
+
+	if (!os_utf8_to_wcs(path, 0, &path_utf16))
+		return MKDIR_ERROR;
+
+	success = CreateDirectory(path_utf16, NULL);
+	bfree(path_utf16);
+
+	if (!success)
+		return (GetLastError() == ERROR_ALREADY_EXISTS) ?
+			MKDIR_EXISTS : MKDIR_ERROR;
+
+	return MKDIR_SUCCESS;
+}
+
 #ifdef PTW32_STATIC_LIB
 
 BOOL WINAPI DllMain(HINSTANCE hinst_dll, DWORD reason, LPVOID reserved)

+ 6 - 0
libobs/util/platform.h

@@ -72,6 +72,12 @@ EXPORT uint64_t os_gettime_ms(void);
 
 EXPORT char *os_get_home_path(void);
 
+#define MKDIR_EXISTS   1
+#define MKDIR_SUCCESS  0
+#define MKDIR_ERROR   -1
+
+EXPORT int os_mkdir(const char *path);
+
 #ifdef _MSC_VER
 EXPORT int fseeko(FILE *stream, off_t offset, int whence);
 EXPORT off_t ftello(FILE *stream);