static char * process_path(const char *path) { char **splits = NULL; int i, j; char *str, *ret; splits = g_strsplit(path, G_DIR_SEPARATOR_S, -1); for (i = 0, j = 0; splits[i]; i++) { if (strcmp(splits[i], ".") == 0) { } else if (strcmp(splits[i], "..") == 0) { if (j) j--; } else { if (i != j) { g_free(splits[j]); splits[j] = splits[i]; splits[i] = NULL; } j++; } } g_free(splits[j]); splits[j] = NULL; str = g_build_pathv(G_DIR_SEPARATOR_S, splits); ret = g_strdup_printf(G_DIR_SEPARATOR_S "%s", str); g_free(str); g_strfreev(splits); return ret; }
/** * Build path to file in xmms2 configuration directory. * @param first The first file or directory name in the path. * @param ... Additional file/directory names. * @return Absolute path to a file or directory. */ char * xmms_build_path (const char *first, ...) { va_list ap; gchar confdir[XMMS_PATH_MAX]; gchar *ret, **vargv, **argv; g_return_val_if_fail (first, NULL); xmms_userconfdir_get (confdir, XMMS_PATH_MAX); va_start (ap, first); vargv = xmms_valist_to_strlist (first, ap); va_end (ap); argv = xmms_strlist_prepend_copy (vargv, confdir); ret = g_build_pathv (G_DIR_SEPARATOR_S, argv); xmms_strlist_destroy (vargv); xmms_strlist_destroy (argv); return ret; }