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

cboesch subversion at mplayerhq.hu
Mon Jan 3 19:37:45 CET 2011


Author: cboesch
Date: Mon Jan  3 19:37:45 2011
New Revision: 32750

Log:
Replace mp_path_is_absolute with mp_path_join.

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

Modified: trunk/path.c
==============================================================================
--- trunk/path.c	Sun Jan  2 20:04:35 2011	(r32749)
+++ trunk/path.c	Mon Jan  3 19:37:45 2011	(r32750)
@@ -238,13 +238,37 @@ char *mp_dirname(const char *path)
 }
 
 /**
- * @brief Indicates weither the path is absolute or not.
+ * @brief Join two paths if path is not absolute.
+ * @param base File or directory base path.
+ * @param path Path to concatenate with the base.
+ * @return New allocated string with the path, or NULL in case of error.
+ * @warning Do not forget the trailing path separator at the end of the base
+ *          path if it is a directory: since file paths are also supported,
+ *          this separator will make the distinction.
+ * @note Paths of the form c:foo, /foo or \foo will still depends on the
+ *       current directory on Windows systems, even though they are considered
+ *       as absolute paths in this function.
  */
-int mp_path_is_absolute(const char *path)
+char *mp_path_join(const char *base, const char *path)
 {
+    char *ret, *tmp;
+
 #if HAVE_DOS_PATHS
-    return path[0] && path[1] == ':';
+    if ((path[0] && path[1] == ':') || path[0] == '\\' || path[0] == '/')
 #else
-    return path[0] == '/';
+    if (path[0] == '/')
 #endif
+        return strdup(path);
+
+    ret = mp_dirname(base);
+    if (!ret)
+        return NULL;
+    tmp = realloc(ret, strlen(ret) + strlen(path) + 1);
+    if (!tmp) {
+        free(ret);
+        return NULL;
+    }
+    ret = tmp;
+    strcat(ret, path);
+    return ret;
 }

Modified: trunk/path.h
==============================================================================
--- trunk/path.h	Sun Jan  2 20:04:35 2011	(r32749)
+++ trunk/path.h	Mon Jan  3 19:37:45 2011	(r32750)
@@ -28,6 +28,6 @@ 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);
-int mp_path_is_absolute(const char *path);
+char *mp_path_join(const char *base, const char *new_path);
 
 #endif /* MPLAYER_PATH_H */


More information about the MPlayer-cvslog mailing list