From 2635d332f07ee1691a785d543f7ccbde2eeb99f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Wed, 13 Aug 2008 14:08:01 +0200 Subject: - Added mp3_basename --- include/mp3fs.h | 1 + src/mp3_subr.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/mp3fs.h b/include/mp3fs.h index 4ecb6c8..300a829 100644 --- a/include/mp3fs.h +++ b/include/mp3fs.h @@ -57,6 +57,7 @@ void mp3_lookup_genre(const char *, struct filler_data *); void mp3_lookup_album(const char *, struct filler_data *); char *mp3_gettoken(const char *, int); int mp3_numtoken(const char *); +char *mp3_basename(const char *); int mp3_file_data_for_path(const char *, void *); enum mp3_filetype mp3_get_filetype(const char *); diff --git a/src/mp3_subr.c b/src/mp3_subr.c index 546bbdd..781b230 100644 --- a/src/mp3_subr.c +++ b/src/mp3_subr.c @@ -508,6 +508,36 @@ mp3_gettoken(const char *str, int toknum) return (ret); } +/* + * Get the basename of a string. (everything before the last ".", or + * the entire string of no "." is found) + */ +char * +mp3_basename(const char *str) +{ + if (!str) + return (NULL); + + char *res = malloc(sizeof(char) * (strlen(str) + 1)); + char *stop = strrchr(str, (int)'.'); + char *p; + const char *q; + + if (stop) { + p = res; + q = str; + while (q != stop) { + *p = *q; + p++; q++; + } + *p = '\0'; + } else { + strcpy(res, str); + } + + return (res); +} + /* * List album given a path. */ -- cgit v1.2.3