Mercurial > hg > th-libs
changeset 741:0852bd106034
Change th_mkdir_path() API, instead if returning boolean, return a th-lib error code.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 14 Dec 2022 01:32:40 +0200 |
parents | caeb0a44ebdf |
children | 64af66cae541 |
files | th_file.c th_file.h |
diffstat | 2 files changed, 15 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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; }
--- 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