# HG changeset patch # User cboesch # Date 1294079865 0 # Node ID 83c490a2e9f37eee657e12a2fcf990ca3aae8270 # Parent d71575a9c5626b4ad53f23e3e58de8b30cdf4d54 Replace mp_path_is_absolute with mp_path_join. diff -r d71575a9c562 -r 83c490a2e9f3 path.c --- a/path.c Sun Jan 02 19:04:35 2011 +0000 +++ b/path.c Mon Jan 03 18:37:45 2011 +0000 @@ -238,13 +238,37 @@ } /** - * @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; } diff -r d71575a9c562 -r 83c490a2e9f3 path.h --- a/path.h Sun Jan 02 19:04:35 2011 +0000 +++ b/path.h Mon Jan 03 18:37:45 2011 +0000 @@ -28,6 +28,6 @@ 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 */