diff options
Diffstat (limited to 'misc.c')
-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) { |