[MPlayer-cvslog] r32641 - in trunk: path.c path.h

cboesch subversion at mplayerhq.hu
Sun Nov 21 18:07:34 CET 2010


Author: cboesch
Date: Sun Nov 21 18:07:34 2010
New Revision: 32641

Log:
Add a mp_dirname function (unused at the moment)

Modified:
   trunk/path.c
   trunk/path.h

Modified: trunk/path.c
==============================================================================
--- trunk/path.c	Sun Nov 21 17:52:22 2010	(r32640)
+++ trunk/path.c	Sun Nov 21 18:07:34 2010	(r32641)
@@ -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;
+}

Modified: trunk/path.h
==============================================================================
--- trunk/path.h	Sun Nov 21 17:52:22 2010	(r32640)
+++ trunk/path.h	Sun Nov 21 18:07:34 2010	(r32641)
@@ -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 */


More information about the MPlayer-cvslog mailing list