提交 847b3df3 编写于 作者: J jp9000

libobs/util: Add os_mkdirs

Recursively creates a directory structure if one or more directories in
the path structure don't exist
上级 bf372584
......@@ -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;
}
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册