# HG changeset patch # User Matti Hamalainen # Date 1670974360 -7200 # Node ID 0852bd106034f6937ef4ad42ac981da6f48daa1a # Parent caeb0a44ebdff9a36f352d2b2f51ba53c7d0b179 Change th_mkdir_path() API, instead if returning boolean, return a th-lib error code. diff -r caeb0a44ebdf -r 0852bd106034 th_file.c --- a/th_file.c Wed Dec 14 01:31:51 2022 +0200 +++ b/th_file.c Wed Dec 14 01:32:40 2022 +0200 @@ -150,11 +150,14 @@ } -bool th_mkdir_path(const char *cpath, const int mode) +int th_mkdir_path(const char *cpath, const int mode) { char save, *path = th_strdup(cpath); size_t start = 0, end; - bool res = false; + int res = THERR_OK; + + if (path == NULL) + return THERR_MALLOC; #if defined(TH_PLAT_WINDOWS) (void) mode; @@ -178,17 +181,22 @@ th_stat_data sdata; bool exists = th_stat_path(path, &sdata); if (exists && (sdata.flags & TH_IS_DIR) == 0) - goto error; + { + res = THERR_FWRITE; + goto out; + } if (!exists) { #if defined(TH_PLAT_WINDOWS) if (!CreateDirectory(path, NULL)) - goto error; #else if (mkdir(path, mode != 0 ? mode : 0711) < 0) - goto error; #endif + { + res = th_get_error(); + goto out; + } } } @@ -197,9 +205,7 @@ start = end + 1; } while (save != 0); - res = true; - -error: +out: th_free(path); return res; } diff -r caeb0a44ebdf -r 0852bd106034 th_file.h --- a/th_file.h Wed Dec 14 01:31:51 2022 +0200 +++ b/th_file.h Wed Dec 14 01:32:40 2022 +0200 @@ -49,7 +49,7 @@ char * th_get_config_dir(void); bool th_stat_path(const char *path, th_stat_data *data); -bool th_mkdir_path(const char *path, const int mode); +int th_mkdir_path(const char *path, const int mode); #ifdef __cplusplus