From 2de000040299e0f8d7d013acdb8cc0e958ece0e7 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Fri, 5 Aug 2022 13:49:59 -0300 Subject: misc: Make `dir_path_name()` actually do some error checking --- misc.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/misc.c b/misc.c index 4a5f6be..75afc20 100644 --- a/misc.c +++ b/misc.c @@ -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) { -- cgit v1.2.3-13-gbd6f