path-util: add path_extract_directory(), to match path_extract_filename()

These two together are a lot like dirname() + basename() but have the
benefit that they return clear errors when one passes a special case
path to them where the extraction doesn't make sense, i.e. "", "/",
"foo", "foo/" and so on.

Sooner or later we should probably port all our uses of
dirname()/basename() over to this, to catch these special cases more
safely.
This commit is contained in:
Lennart Poettering
2021-03-02 15:07:11 +01:00
parent 7e40042b55
commit 8dcb891c19
3 changed files with 102 additions and 0 deletions
+1
View File
@@ -147,6 +147,7 @@ int fsck_exists(const char *fstype);
char* dirname_malloc(const char *path);
const char *last_path_component(const char *path);
int path_extract_filename(const char *p, char **ret);
int path_extract_directory(const char *p, char **ret);
bool filename_is_valid(const char *p) _pure_;
bool path_is_valid(const char *p) _pure_;