[PATCH] Replace mp_path_is_absolute with mp_path_join.
Clément Bœsch
ubitux at gmail.com
Tue Dec 28 21:57:36 CET 2010
---
path.c | 29 +++++++++++++++++++++++++----
path.h | 2 +-
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/path.c b/path.c
index bf6dc5e..c7af93b 100644
--- a/path.c
+++ b/path.c
@@ -238,13 +238,34 @@ char *mp_dirname(const char *path)
}
/**
- * @brief Indicates weither the path is absolute or not.
+ * @brief Join two paths if new 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.
*/
-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;
}
diff --git a/path.h b/path.h
index 75a6182..1369836 100644
--- a/path.h
+++ b/path.h
@@ -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 */
--
1.7.3.4
--IJpNTDwzlM2Ie8A6--
More information about the MPlayer-cvslog
mailing list