added path_getUserDir, dir_createParent
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include "internal.h"
|
||||
|
||||
bool dir_exists(cstr path){
|
||||
if(path == NULL || path[0] == 0)
|
||||
return true;
|
||||
|
||||
if(path[0]=='.'){
|
||||
if(path[1]==0 || (path[1]==path_sep && path[1]==0))
|
||||
return true; // dir . or ./ always exists
|
||||
@@ -23,13 +26,12 @@ bool dir_exists(cstr path){
|
||||
|
||||
Result(bool) dir_create(cstr path){
|
||||
Deferral(4);
|
||||
if (dir_exists(path)){
|
||||
|
||||
if (path == NULL || path[0] == 0 || dir_exists(path)){
|
||||
Return RESULT_VALUE(i, false);
|
||||
}
|
||||
|
||||
char* parentDir= str_copy(path_dirname(str_from_cstr((void*)path))).data;
|
||||
Defer(free(parentDir));
|
||||
try_void(dir_create(parentDir));
|
||||
try_void(dir_createParent(path));
|
||||
|
||||
#if TLIBC_FS_USE_WINDOWS_H
|
||||
if(!CreateDirectory(path, NULL))
|
||||
@@ -47,3 +49,18 @@ Result(bool) dir_create(cstr path){
|
||||
|
||||
Return RESULT_VALUE(i, true);
|
||||
}
|
||||
|
||||
Result(bool) dir_createParent(cstr path){
|
||||
Deferral(4);
|
||||
|
||||
str parent_dir_str = path_dirname(str_from_cstr((void*)path));
|
||||
if(parent_dir_str.len == 0){
|
||||
Return RESULT_VALUE(i, false);
|
||||
}
|
||||
|
||||
char* parent_dir_cstr = str_copy(parent_dir_str).data;
|
||||
Defer(free(parent_dir_cstr));
|
||||
|
||||
try(bool result, i, dir_create(parent_dir_cstr));
|
||||
Return RESULT_VALUE(i, result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user