summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-08-13 14:08:01 +0200
committerKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-08-13 14:08:01 +0200
commit2635d332f07ee1691a785d543f7ccbde2eeb99f0 (patch)
tree52a4326c12b6fc4b9b72dfe331ccc3ed159677e4
parente45c3bb3be985799f8e8162da4f79962dea3018b (diff)
- Added mp3_basename
-rw-r--r--include/mp3fs.h1
-rw-r--r--src/mp3_subr.c30
2 files changed, 31 insertions, 0 deletions
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
@@ -509,6 +509,36 @@ mp3_gettoken(const char *str, int toknum)
}
/*
+ * 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.
*/
void