added os_mkdir to platform functions

This commit is contained in:
jp9000 2013-11-23 23:35:03 -07:00
parent 3c6494a11d
commit fcf7e508a9
3 changed files with 37 additions and 0 deletions

View file

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

View file

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

View file

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