summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authorVincent Douillet <vincent@vdouillet.fr>2024-12-24 11:52:50 +0100
committerVincent Douillet <vincent@vdouillet.fr>2024-12-26 10:49:13 +0100
commit2e04b2c23c66a42372d0ecaea2b0f4b2c7b7c7e5 (patch)
tree9249bb0e9792a11bb27df78a4d93a0b3c0be0b33 /file.c
parent878cd6e8792d5ac03eea59fec9fe8e325440d50c (diff)
delete files
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