libobs/util: Add os_mkdirs

Recursively creates a directory structure if one or more directories in
the path structure don't exist
master
jp9000 2015-07-08 10:00:33 -07:00
parent bf37258469
commit 847b3df322
2 changed files with 37 additions and 0 deletions

View File

@ -508,3 +508,39 @@ int os_dtostr(double value, char *dst, size_t size)
return (int)length;
}
static int recursive_mkdir(char *path)
{
char *last_slash;
int ret;
ret = os_mkdir(path);
if (ret != MKDIR_ERROR)
return ret;
last_slash = strrchr(path, '/');
if (!last_slash)
return MKDIR_ERROR;
*last_slash = 0;
ret = recursive_mkdir(path);
*last_slash = '/';
if (ret == MKDIR_ERROR)
return MKDIR_ERROR;
ret = os_mkdir(path);
return ret;
}
int os_mkdirs(const char *dir)
{
struct dstr dir_str;
int ret;
dstr_init_copy(&dir_str, dir);
dstr_replace(&dir_str, "\\", "/");
ret = recursive_mkdir(dir_str.array);
dstr_free(&dir_str);
return ret;
}

View File

@ -135,6 +135,7 @@ EXPORT int os_rmdir(const char *path);
#define MKDIR_ERROR -1
EXPORT int os_mkdir(const char *path);
EXPORT int os_mkdirs(const char *path);
EXPORT int os_rename(const char *old_path, const char *new_path);
EXPORT int os_copyfile(const char *file_in, const char *file_out);