Mercurial > mplayer.hg
changeset 35378:e900dc6b8d66
Improve add_to_gui_playlist().
Use pointer arithmetic rather than strlen() and rename variables.
Moreover, a non-existing path (although not supposed to happen)
shouldn't be an empty string.
author | ib |
---|---|
date | Sun, 25 Nov 2012 12:24:02 +0000 |
parents | 6e07bbde3e46 |
children | 2b49f4c8c47f |
files | gui/util/list.c |
diffstat | 1 files changed, 10 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/util/list.c Sun Nov 25 11:55:07 2012 +0000 +++ b/gui/util/list.c Sun Nov 25 12:24:02 2012 +0000 @@ -289,29 +289,30 @@ */ int add_to_gui_playlist(const char *what, int how) { - char *filename, *pathname; + const char *file; + char *path; plItem *item; if (!what || (how != PLAYLIST_ITEM_APPEND && how != PLAYLIST_ITEM_INSERT)) return 0; - filename = strdup(mp_basename(what)); - pathname = strdup(what); + file = mp_basename(what); + path = strdup(what); - if (strlen(pathname) - strlen(filename) > 0) - pathname[strlen(pathname) - strlen(filename) - 1] = 0; // we have some path, so remove / at end + if (file > what) + path[file - what - 1] = 0; else - pathname[strlen(pathname) - strlen(filename)] = 0; + strcpy(path, "."); item = calloc(1, sizeof(plItem)); if (!item) return 0; - mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[list] adding %s/%s\n", pathname, filename); + mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[list] adding %s/%s\n", path, file); - item->name = filename; - item->path = pathname; + item->name = strdup(file); + item->path = path; listMgr(how, item);