added bool value return to dir_create

This commit is contained in:
Timerix 2025-08-04 19:15:30 +03:00
parent e1dc972b24
commit 223406d4e4
3 changed files with 7 additions and 6 deletions

View File

@ -43,7 +43,7 @@ typedef struct Result_ {
#define RESULT_ERROR(MSG, IS_MSG_ON_HEAP) (Result_){ .error = Error_create(MSG, IS_MSG_ON_HEAP, ErrorCallPos_here()) }
#define RESULT_ERROR_FMT(FORMAT, ARGS...) RESULT_ERROR(sprintf_malloc(4096, FORMAT ,##ARGS), true)
#define RESULT_ERROR_ERRNO() RESULT_ERROR(strerror(errno), false)
#define RESULT_VOID (Result_){ .error = NULL }
#define RESULT_VOID (Result_){ .error = NULL, .u = 0 }
#define RESULT_VALUE(FIELD, V) (Result_){ .error = NULL, .FIELD = V }
#define try(VAR, RSLT_CALL, DEFER_CODE) \

View File

@ -123,5 +123,6 @@ static inline Result(void) file_readBytesArrayExactly(FILE* f, Array(u8) dst){
bool dir_exists(cstr path);
/// @brief creates directories specified in path recursively if they don't exist
Result(void) dir_create(cstr path);
/// @brief creates directories specified in path recursively
/// @return false if directory was present already, true if it has been created
Result(bool) dir_create(cstr path);

View File

@ -22,9 +22,9 @@ bool dir_exists(cstr path){
#endif
}
Result(void) dir_create(cstr path){
Result(bool) dir_create(cstr path){
if (dir_exists(path))
return RESULT_VOID;
return RESULT_VALUE(i, false);
char* parentDir= str_copy(path_dirname(str_from_cstr((void*)path))).data;
try_void(dir_create(parentDir), free(parentDir));
@ -38,5 +38,5 @@ Result(void) dir_create(cstr path){
return RESULT_ERROR_FMT("Can't create dicectory '%s': %s", path, strerror(errno));
}
return RESULT_VOID;
return RESULT_VALUE(i, true);
}