void _media_util_trim_path(const char *input_path, char **output_path)
{
- char buf[4096] = {0,};
- char tmp[4096] = {0,};
- char *pos = NULL;
-
- memset(buf, 0, sizeof(buf));
- if (!SAFE_STRLCPY(buf, input_path, sizeof(buf)))
- media_content_sec_debug("Truncation occurred[%zu]", strlen(input_path));
-
- while ((pos = strstr(buf, "//")) != NULL) {
- memset(tmp, 0, sizeof(tmp));
- if (!SAFE_STRLCPY(tmp, buf, pos - buf + 1))
- media_content_sec_debug("Truncation occurred");
- SAFE_STRLCAT(tmp, pos + 1, sizeof(tmp));
-
- memset(buf, 0, sizeof(buf));
- if (!SAFE_STRLCPY(buf, tmp, sizeof(buf)))
- media_content_sec_debug("Truncation occurred[%zu]", strlen(tmp));
- }
-
- if (g_str_has_suffix(buf, "/"))
- *output_path = g_strndup(buf, strlen(buf) - 1);
- else
- *output_path = g_strdup(buf);
+ gchar **name_list = NULL;
+ gchar *tmp_path = NULL;
+
+ if (!STRING_VALID(input_path) || output_path == NULL)
+ return;
+
+ /* Workflow example
+ Input : /a/b//c/
+ After g_strsplit() : {'','a','b','','c',''}
+ After g_build_pathv() : a/b/c
+ After g_strdup_printf() : /a/b/c
+ */
+ name_list = g_strsplit(input_path, "/", -1);
+ if (!name_list)
+ return;
+
+ tmp_path = g_build_pathv(G_DIR_SEPARATOR_S, name_list);
+ g_strfreev(name_list);
+ if (!tmp_path)
+ return;
+
+ /* g_build_pathv does not add root '/' */
+ *output_path = g_strdup_printf("/%s", tmp_path);
+ g_free(tmp_path);
}