path: Add l_basename function
PATCH 1/1 path: Add l_basename function
Many ell based projects use the GNU version (obtained using #define _GNU_SOURCE). Unlike the POSIX version, this version does not modify its arguments. However, some libc implementations such as musl, only provide the POSIX implementation. Implement a version of basename in ell.
--- ell/ell.sym | 1 + ell/path.c | 19 +++++++++++++++++++ ell/path.h | 2 ++ 3 files changed, 22 insertions(+)
ell/ell.sym +1 -0
@@ -434,6 +434,7 @@ global: l_netlink_unregister; l_netlink_set_debug; /* path */ + l_basename; l_path_find; l_path_get_mtime; l_path_next;
ell/path.c +19 -0
@@ -173,3 +173,22 @@ LIB_EXPORT int l_path_touch(const char *path)return -errno; } + +/** +* l_basename: +* @path: The path to find the base name of +* +* This function operates similarly to the glibc version of basename. This +* version never modifies its argument and returns the contents in path after +* the last '/' character. Note that this will result in an empty string being +* returned when @path ends in a trailing slash. +*/ +LIB_EXPORT const char *l_basename(const char *path) +{ +const char *p =strrchr (path,'/' ); + +if (p) +return p +1 ; + +return path; +}
ell/path.h +2 -0
@@ -17,6 +17,8 @@ char *l_path_find(const char *basename, const char *path_str, int mode);uint64_t l_path_get_mtime (const char *path);int l_path_touch (const char *path); +const char *l_basename (const char *path); + #ifdef __cplusplus }#endif
Signature · 1 line
2.45.1
Denis Kenzior
AppliedQuoted 11 lines · Denis Kenzior
Many ell based projects use the GNU version (obtained using #define
_GNU_SOURCE). Unlike the POSIX version, this version does not modify its arguments. However, some libc implementations such as musl, only provide the POSIX implementation. Implement a version of basename in ell.--- ell/ell.sym | 1 + ell/path.c | 19 +++++++++++++++++++ ell/path.h | 2 ++ 3 files changed, 22 insertions(+)
Applied.
Regards,
-Denis