Discussion:
[PATCH 1/2] path.h: introduce path_basename()
Gregory Petrosyan
2011-09-29 15:36:55 UTC
Permalink
Signed-off-by: Gregory Petrosyan <***@gmail.com>
---
path.c | 9 +++++++++
path.h | 1 +
ui_curses.c | 10 ++--------
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/path.c b/path.c
index 1863b6b..cf402a4 100644
--- a/path.c
+++ b/path.c
@@ -22,6 +22,15 @@
#include <stdlib.h>
#include <unistd.h>

+const char *path_basename(const char *path)
+{
+ const char *f;
+
+ f = strrchr(path, '/');
+
+ return f ? f + 1 : path;
+}
+
void path_strip(char *str)
{
int i, s, d;
diff --git a/path.h b/path.h
index c83f32e..1d2692a 100644
--- a/path.h
+++ b/path.h
@@ -19,6 +19,7 @@
#ifndef _PATH_H
#define _PATH_H

+const char *path_basename(const char *path);
void path_strip(char *str);
char *path_absolute_cwd(const char *src, const char *cwd);
char *path_absolute(const char *src);
diff --git a/ui_curses.c b/ui_curses.c
index b052ef9..69151b9 100644
--- a/ui_curses.c
+++ b/ui_curses.c
@@ -46,6 +46,7 @@
#include "worker.h"
#include "input.h"
#include "file.h"
+#include "path.h"
#include "mixer.h"
#include "config/curses.h"
#include "config/iconv.h"
@@ -572,14 +573,7 @@ static void fill_track_fopts_track_info(struct track_info *info)
if (is_http_url(info->filename)) {
fopt_set_str(&track_fopts[TF_FILE], filename);
} else {
- const char *f;
-
- f = strrchr(filename, '/');
- if (f) {
- fopt_set_str(&track_fopts[TF_FILE], f + 1);
- } else {
- fopt_set_str(&track_fopts[TF_FILE], filename);
- }
+ fopt_set_str(&track_fopts[TF_FILE], path_basename(filename));
}
}
--
1.7.4.4
Loading...