summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-08-05 13:49:59 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-08-05 13:49:59 -0300
commit2de000040299e0f8d7d013acdb8cc0e958ece0e7 (patch)
tree813253f86ae89b2287f89e6907d0b824d3751d98
parent689f0738581ee6dec440d7123e5431f4a78adaf9 (diff)
misc: Make `dir_path_name()` actually do some error checking
-rw-r--r--misc.c20
1 files 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) {