Code

use g_basename() instead of basename()
authorMax Kellermann <max@duempel.org>
Fri, 3 Oct 2008 09:51:32 +0000 (11:51 +0200)
committerMax Kellermann <max@duempel.org>
Fri, 3 Oct 2008 09:51:32 +0000 (11:51 +0200)
g_basename() is always available, no need to implement a fallback.
Also use g_path_get_dirname(), g_path_get_basename().

configure.ac
src/screen_browser.c
src/screen_file.c
src/strfsong.c
src/support.c
src/support.h

index 8ea3461c8b28c6f2cf8d2324bd88904fd3a27044..732b36f1e93647e1e9aa710b86611e17f0d10be4 100644 (file)
@@ -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
index 1350a56b4b7c134460be439c401cde6dc28c83be..da0dc897c088093376c289f856a3399fe065da56 100644 (file)
@@ -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;
 }
index baec535df502522b4738dc7a2252d306fdd04497..95510a516759dfd466a2f8f072bf617886c0d123 100644 (file)
@@ -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;
 }
 
index fcaf4ada1673cbef53401b91f3527eb2186ea11c..cef2056c8b89b9d5e6bb49d85921f0d677ae6b7e 100644 (file)
@@ -23,7 +23,6 @@
  */
 
 #include "strfsong.h"
-#include "support.h"
 #include "charset.h"
 
 #include <string.h>
@@ -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) {
index ca0266c1be28da9816a65ae6bf2a12c8badb429b..3ceac5a3a0d294450663497148fb6537ac584bfa 100644 (file)
@@ -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)
index 68f746dd3590af88ef8a65e8e31b148cb2428fd5..305ecbcf19d3fde468f3ea1cfe2d48a0aecbe97a 100644 (file)
@@ -7,10 +7,6 @@
 #include <libgen.h>
 #endif
 
-#ifndef HAVE_BASENAME
-char *basename(char *path);
-#endif
-
 char *remove_trailing_slash(char *path);
 const char *strcasestr(const char *haystack, const char *needle);