diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2022-08-05 13:49:59 -0300 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2022-08-05 13:49:59 -0300 |
commit | 2de000040299e0f8d7d013acdb8cc0e958ece0e7 (patch) | |
tree | 813253f86ae89b2287f89e6907d0b824d3751d98 | |
parent | 689f0738581ee6dec440d7123e5431f4a78adaf9 (diff) |
misc: Make `dir_path_name()` actually do some error checking
-rw-r--r-- | misc.c | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -131,12 +131,20 @@ char *dir_path_num(const char *root, int num) { } char *dir_path_name(const char *root, char *name) { - /* Get the length of the path. */ - int len = snprintf(NULL, 0, "%s/%s", root, name); - /* Create the directory path. */ - char *dir = calloc(len+1, sizeof(char)); - sprintf(dir, "%s/%s", root, name); - return dir; + if (!is_empty(root)) { + if (!is_empty(name)) { + /* Get the length of the path. */ + int len = snprintf(NULL, 0, "%s/%s", root, name); + /* Create the directory path. */ + char *dir = calloc(len+1, sizeof(char)); + sprintf(dir, "%s/%s", root, name); + return dir; + } else { + return make_str(root); + } + } else { + return NULL; + } } int delm_span(char *str, const char delm) { |