added bool value return to dir_create
This commit is contained in:
parent
e1dc972b24
commit
223406d4e4
@ -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(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_FMT(FORMAT, ARGS...) RESULT_ERROR(sprintf_malloc(4096, FORMAT ,##ARGS), true)
|
||||||
#define RESULT_ERROR_ERRNO() RESULT_ERROR(strerror(errno), false)
|
#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 RESULT_VALUE(FIELD, V) (Result_){ .error = NULL, .FIELD = V }
|
||||||
|
|
||||||
#define try(VAR, RSLT_CALL, DEFER_CODE) \
|
#define try(VAR, RSLT_CALL, DEFER_CODE) \
|
||||||
|
|||||||
@ -123,5 +123,6 @@ static inline Result(void) file_readBytesArrayExactly(FILE* f, Array(u8) dst){
|
|||||||
|
|
||||||
bool dir_exists(cstr path);
|
bool dir_exists(cstr path);
|
||||||
|
|
||||||
/// @brief creates directories specified in path recursively if they don't exist
|
/// @brief creates directories specified in path recursively
|
||||||
Result(void) dir_create(cstr path);
|
/// @return false if directory was present already, true if it has been created
|
||||||
|
Result(bool) dir_create(cstr path);
|
||||||
|
|||||||
@ -22,9 +22,9 @@ bool dir_exists(cstr path){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Result(void) dir_create(cstr path){
|
Result(bool) dir_create(cstr path){
|
||||||
if (dir_exists(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;
|
char* parentDir= str_copy(path_dirname(str_from_cstr((void*)path))).data;
|
||||||
try_void(dir_create(parentDir), free(parentDir));
|
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_ERROR_FMT("Can't create dicectory '%s': %s", path, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
return RESULT_VOID;
|
return RESULT_VALUE(i, true);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user