From 482fe8bf05d9d95fa262be3bd815d686740bf449 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 28 Sep 2008 16:30:33 -0700 Subject: path: add mpd_basename() function This is like basename(3) but with predictable semantics independent of C library or build options used. This is also much more strict and does not account for trailing slashes (mpd should never deal with trailing slashes on internal functions). --- src/path.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/path.c') diff --git a/src/path.c b/src/path.c index ceb00c5de..8d1b0018d 100644 --- a/src/path.c +++ b/src/path.c @@ -290,3 +290,15 @@ void utf8_to_fs_playlist_path(char *path_max_tmp, const char *utf8path) rpp2app_r(path_max_tmp, path_max_tmp); strncat(path_max_tmp, "." PLAYLIST_FILE_SUFFIX, MPD_PATH_MAX - 1); } + +/* Only takes sanitized paths w/o trailing slashes */ +const char *mpd_basename(const char *path) +{ + const char *ret = strrchr(path, '/'); + + if (!ret) + return path; + ++ret; + assert(*ret != '\0'); + return ret; +} -- cgit v1.2.3