From 44ecb3b869a8106475b984b4a0d212f9b3b3a219 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 3 Oct 2008 11:51:32 +0200 Subject: [PATCH] use g_basename() instead of basename() g_basename() is always available, no need to implement a fallback. Also use g_path_get_dirname(), g_path_get_basename(). --- configure.ac | 2 +- src/screen_browser.c | 8 ++++---- src/screen_file.c | 16 +++++++--------- src/strfsong.c | 3 +-- src/support.c | 22 ---------------------- src/support.h | 4 ---- 6 files changed, 13 insertions(+), 42 deletions(-) diff --git a/configure.ac b/configure.ac index 8ea3461..732b36f 100644 --- a/configure.ac +++ b/configure.ac @@ -44,7 +44,7 @@ AC_CHECK_HEADER([locale.h], dnl dnl Check for functions dnl -AC_CHECK_FUNCS([basename strcasestr]) +AC_CHECK_FUNCS([strcasestr]) dnl diff --git a/src/screen_browser.c b/src/screen_browser.c index 1350a56..da0dc89 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -21,7 +21,6 @@ #include "i18n.h" #include "options.h" #include "charset.h" -#include "support.h" #include "strfsong.h" #include "screen_utils.h" #include "gcc.h" @@ -136,7 +135,7 @@ browser_lw_callback(unsigned idx, int *highlight, void *data) if( entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY ) { mpd_Directory *dir = entity->info.directory; - char *directory = utf8_to_locale(basename(dir->path)); + char *directory = utf8_to_locale(g_basename(dir->path)); g_snprintf(buf, BUFSIZE, "[%s]", directory); g_free(directory); @@ -148,7 +147,7 @@ browser_lw_callback(unsigned idx, int *highlight, void *data) return buf; } else if( entity->type==MPD_INFO_ENTITY_TYPE_PLAYLISTFILE ) { mpd_PlaylistFile *plf = entity->info.playlistFile; - char *filename = utf8_to_locale(basename(plf->path)); + char *filename = utf8_to_locale(g_basename(plf->path)); g_snprintf(buf, BUFSIZE, playlist_format, filename); g_free(filename); @@ -213,7 +212,8 @@ load_playlist(mpdclient_t *c, filelist_entry_t *entry) char *filename = utf8_to_locale(plf->path); if (mpdclient_cmd_load_playlist_utf8(c, plf->path) == 0) - screen_status_printf(_("Loading playlist %s..."), basename(filename)); + screen_status_printf(_("Loading playlist %s..."), + g_basename(filename)); g_free(filename); return 0; } diff --git a/src/screen_file.c b/src/screen_file.c index baec535..95510a5 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -20,7 +20,6 @@ #include "i18n.h" #include "options.h" #include "charset.h" -#include "support.h" #include "mpdclient.h" #include "command.h" #include "screen.h" @@ -121,7 +120,7 @@ handle_delete(screen_t *screen, mpdclient_t *c) } plf = entity->info.playlistFile; - str = utf8_to_locale(basename(plf->path)); + str = utf8_to_locale(g_basename(plf->path)); buf = g_strdup_printf(_("Delete playlist %s [%s/%s] ? "), str, YES, NO); g_free(str); key = tolower(screen_getch(screen->status_window.w, buf)); @@ -176,12 +175,10 @@ browse_open(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c) static const char * browse_title(char *str, size_t size) { - char *pathcopy; - char *parentdir; + char *dirname, *parentdir; - pathcopy = strdup(browser.filelist->path); - parentdir = dirname(pathcopy); - parentdir = basename(parentdir); + dirname = g_path_get_dirname(browser.filelist->path); + parentdir = g_path_get_basename(dirname); if( parentdir[0] == '.' && strlen(parentdir) == 1 ) { parentdir = NULL; @@ -190,8 +187,9 @@ browse_title(char *str, size_t size) g_snprintf(str, size, _("Browse: %s%s%s"), parentdir ? parentdir : "", parentdir ? "/" : "", - basename(browser.filelist->path)); - free(pathcopy); + g_basename(browser.filelist->path)); + free(dirname); + free(parentdir); return str; } diff --git a/src/strfsong.c b/src/strfsong.c index fcaf4ad..cef2056 100644 --- a/src/strfsong.c +++ b/src/strfsong.c @@ -23,7 +23,6 @@ */ #include "strfsong.h" -#include "support.h" #include "charset.h" #include @@ -171,7 +170,7 @@ _strfsong(gchar *s, if( strstr(song->file, "://") ) temp = utf8_to_locale(song->file); else - temp = utf8_to_locale(basename(song->file)); + temp = utf8_to_locale(g_basename(song->file)); } else if (strncmp("%time%", p, n) == 0) { if (song->time != MPD_SONG_NO_TIME) { if (song->time > 3600) { diff --git a/src/support.c b/src/support.c index ca0266c..3ceac5a 100644 --- a/src/support.c +++ b/src/support.c @@ -43,28 +43,6 @@ remove_trailing_slash(char *path) return path; } -#ifndef HAVE_BASENAME -char * -basename(char *path) -{ - char *end; - - assert(path != NULL); - - path = remove_trailing_slash(path); - end = path + strlen(path); - - while (end > path && *end != '/') - end--; - - if (*end == '/' && end != path) - return end+1; - - return path; -} -#endif /* HAVE_BASENAME */ - - #ifndef HAVE_STRCASESTR const char * strcasestr(const char *haystack, const char *needle) diff --git a/src/support.h b/src/support.h index 68f746d..305ecbc 100644 --- a/src/support.h +++ b/src/support.h @@ -7,10 +7,6 @@ #include #endif -#ifndef HAVE_BASENAME -char *basename(char *path); -#endif - char *remove_trailing_slash(char *path); const char *strcasestr(const char *haystack, const char *needle); -- 2.30.2