From 2e04b2c23c66a42372d0ecaea2b0f4b2c7b7c7e5 Mon Sep 17 00:00:00 2001 From: Vincent Douillet Date: Tue, 24 Dec 2024 11:52:50 +0100 Subject: delete files --- file.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'file.c') 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 -- cgit v1.2.3