diff --git a/docs/reference/gio/gio-sections-common.txt b/docs/reference/gio/gio-sections-common.txt index f5737ef42..805768785 100644 --- a/docs/reference/gio/gio-sections-common.txt +++ b/docs/reference/gio/gio-sections-common.txt @@ -90,6 +90,7 @@ g_file_new_tmp_dir_async g_file_new_tmp_dir_finish g_file_parse_name g_file_new_build_filename +g_file_new_build_filenamev g_file_dup g_file_hash g_file_equal diff --git a/gio/gfile.c b/gio/gfile.c index a78737773..bd3bc585e 100644 --- a/gio/gfile.c +++ b/gio/gfile.c @@ -106,7 +106,7 @@ typedef off_t loff_t; * - g_file_new_tmp_async() to asynchronously create a temporary file. * - g_file_new_tmp_dir_async() to asynchronously create a temporary directory. * - g_file_parse_name() from a UTF-8 string gotten from g_file_get_parse_name(). - * - g_file_new_build_filename() to create a file from path elements. + * - g_file_new_build_filename() or g_file_new_build_filenamev() to create a file from path elements. * * One way to think of a #GFile is as an abstraction of a pathname. For * normal files the system pathname is what is stored internally, but as @@ -7406,6 +7406,35 @@ g_file_new_build_filename (const gchar *first_element, return file; } + +/** + * g_file_new_build_filenamev: + * @args: (array zero-terminated=1) (element-type filename): %NULL-terminated + * array of strings containing the path elements. + * + * Constructs a #GFile from a vector of elements using the correct + * separator for filenames. + * + * Using this function is equivalent to calling g_build_filenamev(), + * followed by g_file_new_for_path() on the result. + * + * Returns: (transfer full): a new #GFile + * + * Since: 2.78 + */ +GFile * +g_file_new_build_filenamev (const gchar * const *args) +{ + gchar *str; + GFile *file; + + str = g_build_filenamev ((gchar **) args); + file = g_file_new_for_path (str); + g_free (str); + + return file; +} + static gboolean is_valid_scheme_character (char c) { diff --git a/gio/gfile.h b/gio/gfile.h index 141435f40..7c43fe070 100644 --- a/gio/gfile.h +++ b/gio/gfile.h @@ -650,6 +650,8 @@ GFile * g_file_parse_name (const char GIO_AVAILABLE_IN_2_56 GFile * g_file_new_build_filename (const gchar *first_element, ...) G_GNUC_NULL_TERMINATED; +GIO_AVAILABLE_IN_2_78 +GFile * g_file_new_build_filenamev (const gchar * const *args); GIO_AVAILABLE_IN_ALL GFile * g_file_dup (GFile *file); GIO_AVAILABLE_IN_ALL diff --git a/gio/tests/file.c b/gio/tests/file.c index 61109909d..69c25ff69 100644 --- a/gio/tests/file.c +++ b/gio/tests/file.c @@ -61,6 +61,22 @@ test_build_filename (void) g_object_unref (file); } +static void +test_build_filenamev (void) +{ + GFile *file; + + const gchar *args[] = { ".", "some", "directory", "testfile", NULL }; + file = g_file_new_build_filenamev (args); + test_basic_for_file (file, "/some/directory/testfile"); + g_object_unref (file); + + const gchar *brgs[] = { "testfile", NULL }; + file = g_file_new_build_filenamev (brgs); + test_basic_for_file (file, "/testfile"); + g_object_unref (file); +} + static void test_parent (void) { @@ -3928,6 +3944,7 @@ main (int argc, char *argv[]) g_test_add_func ("/file/basic", test_basic); g_test_add_func ("/file/build-filename", test_build_filename); + g_test_add_func ("/file/build-filenamev", test_build_filenamev); g_test_add_func ("/file/parent", test_parent); g_test_add_func ("/file/child", test_child); g_test_add_func ("/file/empty-path", test_empty_path);