added defer macro

This commit is contained in:
2025-08-09 21:38:40 +03:00
parent fe9e44a660
commit d04aac567f
3 changed files with 126 additions and 22 deletions

View File

@@ -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);
}