diff --git a/src/host/os_mkdir.c b/src/host/os_mkdir.c index a7a69db4..e572c349 100644 --- a/src/host/os_mkdir.c +++ b/src/host/os_mkdir.c @@ -8,26 +8,49 @@ #include "premake.h" -int os_mkdir(lua_State* L) +int do_mkdir(const char* path) { - int z; - const char* path = luaL_checkstring(L, 1); + char sub_path[2048]; + int i, z; + + size_t path_length = strlen(path); + for (i = 0; i < path_length; ++i) + { + if (path[i] == '/' || path[i] == '\\') + { + memcpy(sub_path, path, i); + sub_path[i] = '\0'; #if PLATFORM_WINDOWS - z = CreateDirectory(path, NULL); + z = CreateDirectory(sub_path, NULL); #else - z = (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0); + z = (mkdir(sub_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0); #endif + if (!z) + { + return FALSE; + } + } + } + + return TRUE; +} + + +int os_mkdir(lua_State* L) +{ + const char* path = luaL_checkstring(L, 1); + + int z = do_mkdir(path); if (!z) { lua_pushnil(L); lua_pushfstring(L, "unable to create directory '%s'", path); return 2; } - else - { - lua_pushboolean(L, 1); - return 1; - } + + lua_pushboolean(L, 1); + return 1; } + diff --git a/src/host/zip_extract.c b/src/host/zip_extract.c index 67e88ef9..c5873e8e 100644 --- a/src/host/zip_extract.c +++ b/src/host/zip_extract.c @@ -86,27 +86,7 @@ static int write_link(const char* filename, const char* bytes, size_t count) #endif } -static void r_mkdir(const char* full_path) -{ - size_t path_length = strlen(full_path); - size_t i; - for (i = 0; i < path_length; ++i) - { - if (full_path[i] == '/' || full_path[i] == '\\') - { - char* sub_path = (char*)malloc(i + 1); - memcpy(sub_path, full_path, i); - sub_path[i] = 0; -#if PLATFORM_WINDOWS - _mkdir(sub_path); -#else - mkdir(sub_path, 0755); -#endif - free(sub_path); - } - } -} - +extern int do_mkdir(const char* path); static void parse_path(const char* full_name, char* filename, char* directory) { @@ -171,7 +151,7 @@ static int extract(const char* src, const char* destination) sprintf(appended_full_name, "%s/%s", destination, full_name); parse_path(appended_full_name, filename, directory); - r_mkdir(directory); + do_mkdir(directory); // is this a symbolic link? if (is_symlink(opsys, attrib))