summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'file.c')
-rw-r--r--file.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/file.c b/file.c
index cd76def..efa581d 100644
--- a/file.c
+++ b/file.c
@@ -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