added vfs_path_build_filename() function

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2011-07-17 19:59:47 +03:00
parent aecdc1a32e
commit a959d2843f
4 changed files with 49 additions and 5 deletions

View File

@ -206,6 +206,7 @@ gboolean mc_util_unlink_backup_if_possible (const char *, const char *);
char *guess_message_value (void);
char *mc_build_filename (const char *first_element, ...);
char *mc_build_filenamev (const char *first_element, va_list args);
/*** inline functions **************************************************/

View File

@ -1018,10 +1018,9 @@ get_user_permissions (struct stat *st)
*/
char *
mc_build_filename (const char *first_element, ...)
mc_build_filenamev (const char *first_element, va_list args)
{
gboolean absolute;
va_list args;
const char *element = first_element;
GString *path;
char *ret;
@ -1030,7 +1029,6 @@ mc_build_filename (const char *first_element, ...)
return NULL;
path = g_string_new ("");
va_start (args, first_element);
absolute = (*first_element != '\0' && *first_element == PATH_SEP);
@ -1061,8 +1059,6 @@ mc_build_filename (const char *first_element, ...)
}
while (element != NULL);
va_end (args);
if (absolute)
g_string_prepend_c (path, PATH_SEP);
@ -1073,3 +1069,24 @@ mc_build_filename (const char *first_element, ...)
}
/* --------------------------------------------------------------------------------------------- */
/**
* Build filename from arguments.
* Like to g_build_filename(), but respect VFS_PATH_URL_DELIMITER
*/
char *
mc_build_filename (const char *first_element, ...)
{
va_list args;
char *ret;
if (first_element == NULL)
return NULL;
va_start (args, first_element);
ret = mc_build_filenamev (first_element, args);
va_end (args);
return ret;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -1045,3 +1045,28 @@ vfs_path_deserialize (const char *data, GError ** error)
}
/* --------------------------------------------------------------------------------------------- */
/**
* Build vfs_path_t object from arguments.
*
* return newly allocated vfs_path_t object
*/
vfs_path_t *
vfs_path_build_filename (const char *first_element, ...)
{
va_list args;
char *str_path;
vfs_path_t *vpath;
if (first_element == NULL)
return NULL;
va_start (args, first_element);
str_path = mc_build_filenamev (first_element, args);
va_end (args);
vpath = vfs_path_from_str (str_path);
g_free (str_path);
return vpath;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -57,6 +57,7 @@ char *vfs_path_to_str (const vfs_path_t * path);
char *vfs_path_to_str_elements_count (const vfs_path_t * path, int elements_count);
vfs_path_t *vfs_path_from_str (const char *path_str);
vfs_path_t *vfs_path_from_str_flags (const char *path_str, vfs_path_flag_t flags);
vfs_path_t *vfs_path_build_filename (const char *first_element, ...);
vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);