added defer macro
This commit is contained in:
@@ -23,20 +23,23 @@ bool dir_exists(cstr path){
|
||||
}
|
||||
|
||||
Result(bool) dir_create(cstr path){
|
||||
if (dir_exists(path))
|
||||
return RESULT_VALUE(i, false);
|
||||
Deferral(4);
|
||||
if (dir_exists(path)){
|
||||
Return RESULT_VALUE(i, false);
|
||||
}
|
||||
|
||||
char* parentDir= str_copy(path_dirname(str_from_cstr((void*)path))).data;
|
||||
try_void(dir_create(parentDir), free(parentDir));
|
||||
free(parentDir);
|
||||
Defer(free(parentDir));
|
||||
try_void(dir_create(parentDir));
|
||||
|
||||
#if TLIBC_FS_USE_WINDOWS_H
|
||||
if(!CreateDirectory(path, NULL))
|
||||
#else
|
||||
if(mkdir(path, 0777) == -1)
|
||||
#endif
|
||||
{
|
||||
return RESULT_ERROR_FMT("Can't create dicectory '%s': %s", path, strerror(errno));
|
||||
Return RESULT_ERROR_FMT("Can't create dicectory '%s': %s", path, strerror(errno));
|
||||
}
|
||||
|
||||
return RESULT_VALUE(i, true);
|
||||
Return RESULT_VALUE(i, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user