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

cboesch subversion at mplayerhq.hu
Tue Feb 1 20:17:33 CET 2011


Author: cboesch
Date: Tue Feb  1 20:17:33 2011
New Revision: 32838

Log:
Add mp_dir_join function.

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

Modified: trunk/path.c
==============================================================================
--- trunk/path.c	Mon Jan 31 16:45:46 2011	(r32837)
+++ trunk/path.c	Tue Feb  1 20:17:33 2011	(r32838)
@@ -272,3 +272,34 @@ char *mp_path_join(const char *base, con
     strcat(ret, path);
     return ret;
 }
+
+/**
+ * @brief Same as mp_path_join but always treat the first parameter as a
+ *        directory.
+ * @param dir Directory base path.
+ * @param append Right part to append to dir.
+ * @return New allocated string with the path, or NULL in case of error.
+ */
+char *mp_dir_join(const char *dir, const char *append)
+{
+    char *tmp, *ret;
+    size_t dirlen = strlen(dir);
+    size_t i      = dirlen - 1;
+
+#if HAVE_DOS_PATHS
+    if ((dirlen == 2 && dir[0] && dir[1] == ':') // "X:" only
+        || dirlen == 0 || dir[i] == '\\' || dir[i] == '/')
+#else
+    if (dirlen == 0 || dir[i] == '/')
+#endif
+        return mp_path_join(dir, append);
+
+    tmp = malloc(dirlen + 2);
+    if (!tmp)
+        return NULL;
+    strcpy(tmp, dir);
+    strcpy(tmp + dirlen, "/");
+    ret = mp_path_join(tmp, append);
+    free(tmp);
+    return ret;
+}

Modified: trunk/path.h
==============================================================================
--- trunk/path.h	Mon Jan 31 16:45:46 2011	(r32837)
+++ trunk/path.h	Tue Feb  1 20:17:33 2011	(r32838)
@@ -29,5 +29,6 @@ void set_codec_path(const char *path);
 const char *mp_basename(const char *path);
 char *mp_dirname(const char *path);
 char *mp_path_join(const char *base, const char *new_path);
+char *mp_dir_join(const char *dir, const char *append);
 
 #endif /* MPLAYER_PATH_H */


More information about the MPlayer-cvslog mailing list