diff options
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -140,8 +140,24 @@ file_get_basename(const struct file * f) if (strrchr(f->path, '/') == NULL) return f->path; - /* split for the basename */ - return str_split(f->path, '/'); + /* get the basename */ + return str_tail(f->path, '/'); +} + +struct file * +file_get_parent(const struct file * f) +{ + char *head; + struct file *parent; + + head = str_head(f->path, '/'); + if (head == NULL) + return file_new(""); + + parent = file_new(head); + + free(head); + return parent; } size_t |