# HG changeset patch # User cboesch # Date 1296587853 0 # Node ID 8e7537586f0b76faecd9f7ef2f232536a5d6b0d7 # Parent 8d6e84f970bef3add8eaa9c04b4b638bb0dab5c8 Add mp_dir_join function. diff -r 8d6e84f970be -r 8e7537586f0b path.c --- a/path.c Mon Jan 31 15:45:46 2011 +0000 +++ b/path.c Tue Feb 01 19:17:33 2011 +0000 @@ -272,3 +272,34 @@ 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; +} diff -r 8d6e84f970be -r 8e7537586f0b path.h --- a/path.h Mon Jan 31 15:45:46 2011 +0000 +++ b/path.h Tue Feb 01 19:17:33 2011 +0000 @@ -29,5 +29,6 @@ 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 */