[PATCH 1/3] Add mp_dirname

Clément Bœsch ubitux at gmail.com
Sat Nov 20 18:37:54 CET 2010


---
 path.c |   24 ++++++++++++++++++++++++
 path.h |    1 +
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/path.c b/path.c
index bb1da4d..9d92394 100644
--- a/path.c
+++ b/path.c
@@ -206,3 +206,27 @@ const char *mp_basename(const char *path)
     s = strrchr(path, '/');
     return s ? s + 1 : path;
 }
+
+/**
+ * \brief Allocates a new buffer containing the directory name
+ * \param path Original path. Must be a valid string.
+ *
+ * The path returned always contains a trailing slash '/'.
+ * On systems supporting DOS paths, '\' is also considered as a directory
+ * separator in addition to the '/'.
+ */
+char *mp_dirname(const char *path)
+{
+    const char *base = mp_basename(path);
+    size_t len = base - path;
+    char *dirname;
+
+    if (len == 0)
+        return strdup("./");
+    dirname = malloc(len + 1);
+    if (!dirname)
+        return NULL;
+    strncpy(dirname, path, len);
+    dirname[len] = '\0';
+    return dirname;
+}
diff --git a/path.h b/path.h
index 349f55e..dddbd19 100644
--- a/path.h
+++ b/path.h
@@ -27,5 +27,6 @@ char *get_path(const char *filename);
 void set_path_env(void);
 void set_codec_path(const char *path);
 const char *mp_basename(const char *path);
+char *mp_dirname(const char *path);
 
 #endif /* MPLAYER_PATH_H */
-- 
1.7.3.2


--JBi0ZxuS5uaEhkUZ
Content-Type: text/plain; charset=utf-8
Content-Disposition: attachment; filename="0002-Make-load-of-n-subtitles-directories-possible.patch"



More information about the MPlayer-dev-eng mailing list