aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-20 22:18:12 +0200
committerMax Kellermann <max@duempel.org>2008-10-20 22:18:12 +0200
commitba96920a52bbd2208aa1f3b284edc864e26198ce (patch)
tree6750d817780ef892d82e0ce0aecaebd54546799a /src
parent99e82a2ef293429e3fcc4f6e5d8e7981b4351c7c (diff)
downloadmpd-ba96920a52bbd2208aa1f3b284edc864e26198ce.tar.gz
mpd-ba96920a52bbd2208aa1f3b284edc864e26198ce.tar.xz
mpd-ba96920a52bbd2208aa1f3b284edc864e26198ce.zip
path: replaced mpd_basename() with g_path_get_basename()
GLib's g_path_get_basename() is much more reliable than mpd_basename(). The latter could be tricked into an assertion failure.
Diffstat (limited to 'src')
-rw-r--r--src/directory.c3
-rw-r--r--src/directory_save.c5
-rw-r--r--src/dirvec.c10
-rw-r--r--src/path.c12
-rw-r--r--src/path.h8
-rw-r--r--src/update.c21
6 files changed, 30 insertions, 29 deletions
diff --git a/src/directory.c b/src/directory.c
index f11695a95..ba1ae8560 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -22,6 +22,7 @@
#include <assert.h>
#include <string.h>
+#include <glib.h>
struct directory *
directory_new(const char *path, struct directory *parent)
@@ -53,7 +54,7 @@ directory_free(struct directory *directory)
const char *
directory_get_name(const struct directory *directory)
{
- return mpd_basename(directory->path);
+ return g_basename(directory->path);
}
void
diff --git a/src/directory_save.c b/src/directory_save.c
index 51c51c48c..7ee5cbb02 100644
--- a/src/directory_save.c
+++ b/src/directory_save.c
@@ -24,6 +24,8 @@
#include "utils.h"
#include "song_save.h"
+#include <glib.h>
+
/* TODO error checking */
int
directory_save(FILE *fp, struct directory *directory)
@@ -41,9 +43,10 @@ directory_save(FILE *fp, struct directory *directory)
for (i = 0; i < children->nr; ++i) {
struct directory *cur = children->base[i];
- const char *base = mpd_basename(cur->path);
+ char *base = g_path_get_basename(cur->path);
retv = fprintf(fp, DIRECTORY_DIR "%s\n", base);
+ g_free(base);
if (retv < 0)
return -1;
if (directory_save(fp, cur) < 0)
diff --git a/src/dirvec.c b/src/dirvec.c
index 98cb9e7ad..61e5a859a 100644
--- a/src/dirvec.c
+++ b/src/dirvec.c
@@ -4,6 +4,7 @@
#include "path.h"
#include <string.h>
+#include <glib.h>
static size_t dv_size(struct dirvec *dv)
{
@@ -25,13 +26,18 @@ void dirvec_sort(struct dirvec *dv)
struct directory *dirvec_find(const struct dirvec *dv, const char *path)
{
+ char *basename;
int i;
- path = mpd_basename(path);
+ basename = g_path_get_basename(path);
for (i = dv->nr; --i >= 0; )
- if (!strcmp(directory_get_name(dv->base[i]), path))
+ if (!strcmp(directory_get_name(dv->base[i]), basename)) {
+ g_free(basename);
return dv->base[i];
+ }
+
+ g_free(basename);
return NULL;
}
diff --git a/src/path.c b/src/path.c
index 159d923da..14cb34ea9 100644
--- a/src/path.c
+++ b/src/path.c
@@ -276,15 +276,3 @@ 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;
-}
diff --git a/src/path.h b/src/path.h
index 5230ce37c..62e7acc03 100644
--- a/src/path.h
+++ b/src/path.h
@@ -83,12 +83,4 @@ void pathcpy_trunc(char *dest, const char *src);
*/
void utf8_to_fs_playlist_path(char *path_max_tmp, const char *utf8path);
-/*
- * 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).
- */
-const char *mpd_basename(const char *path);
-
#endif
diff --git a/src/update.c b/src/update.c
index 58a55cf9c..5ab75d7ac 100644
--- a/src/update.c
+++ b/src/update.c
@@ -32,6 +32,8 @@
#include "update.h"
#include "idle.h"
+#include <glib.h>
+
static enum update_progress {
UPDATE_PROGRESS_IDLE = 0,
UPDATE_PROGRESS_RUNNING = 1,
@@ -407,6 +409,7 @@ static struct directory *
directory_make_child_checked(struct directory *parent, const char *path)
{
struct directory *directory;
+ char *basename;
struct stat st;
struct song *conflicting;
@@ -414,16 +417,22 @@ directory_make_child_checked(struct directory *parent, const char *path)
if (directory != NULL)
return directory;
- if (stat_directory_child(parent, mpd_basename(path), &st) < 0 ||
- inodeFoundInParent(parent, st.st_ino, st.st_dev))
+ basename = g_path_get_basename(path);
+
+ if (stat_directory_child(parent, basename, &st) < 0 ||
+ inodeFoundInParent(parent, st.st_ino, st.st_dev)) {
+ g_free(basename);
return NULL;
+ }
/* if we're adding directory paths, make sure to delete filenames
with potentially the same name */
- conflicting = songvec_find(&parent->songs, mpd_basename(path));
+ conflicting = songvec_find(&parent->songs, basename);
if (conflicting)
delete_song(parent, conflicting);
+ g_free(basename);
+
directory = directory_new_child(parent, path);
directory_set_stat(directory, &st);
return directory;
@@ -455,19 +464,21 @@ static void
updatePath(const char *path)
{
struct directory *parent;
- const char *name;
+ char *name;
struct stat st;
parent = addParentPathToDB(path);
if (parent == NULL)
return;
- name = mpd_basename(path);
+ name = g_path_get_basename(path);
if (stat_directory_child(parent, name, &st) == 0)
updateInDirectory(parent, name, &st);
else
delete_name_in(parent, name);
+
+ g_free(name);
}
static void * update_task(void *_path)