# HG changeset patch # User Paul Boddie # Date 1644795775 -3600 # Node ID d7d0949c25fccaef8e111e16336ef89a499a06a9 # Parent f3ae5c354fe42309ef0f2e748094efff9d99fe25 Added a path splitting function to expose a path's dirname and basename. diff -r f3ae5c354fe4 -r d7d0949c25fc libe2access/include/e2access/path.h --- a/libe2access/include/e2access/path.h Sun Feb 13 01:46:28 2022 +0100 +++ b/libe2access/include/e2access/path.h Mon Feb 14 00:42:55 2022 +0100 @@ -1,7 +1,7 @@ /* * Path functions. * - * Copyright (C) 2019 Paul Boddie + * Copyright (C) 2019, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -30,6 +30,7 @@ const char *path_component_end(const char *path); const char *path_component_next(const char *end); int path_is_leafname(const char *path); +char *path_split(char *path); #ifdef __cplusplus } diff -r f3ae5c354fe4 -r d7d0949c25fc libe2access/lib/src/path.c --- a/libe2access/lib/src/path.c Sun Feb 13 01:46:28 2022 +0100 +++ b/libe2access/lib/src/path.c Mon Feb 14 00:42:55 2022 +0100 @@ -1,7 +1,7 @@ /* * Path functions. * - * Copyright (C) 2019 Paul Boddie + * Copyright (C) 2019, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -64,3 +64,19 @@ { return strchr(path, (int) '/') == NULL; } + +/* Split a path into directory and basename components, returning a pointer to + the basename component. */ + +char *path_split(char *path) +{ + char *s = strrchr(path, (int) '/'); + + if (s != NULL) + { + *s = '\0'; + return s + 1; + } + else + return path; +}