GNOME Bugzilla – Bug 788488
GFile-based API for g_build_filename()
Last modified: 2017-11-07 16:26:10 UTC
I find myself writing a lot of code like char *path = g_build_filename (...); GFile *file = g_file_new_for_path (path); It would be nice to have an e.g. g_file_build () API that combined the two for convenience.
Agreed. Patch very much welcome, although I would perhaps call it g_file_new_build_path() instead so it gets recognised as a constructor in bindings.
Created attachment 362942 [details] [review] gio: add g_file_new_build_filename() convenience API This is equivalent to calling g_file_new_for_path() on the result of g_build_filename(), and is provided for convenience to C clients.
Here's a first attempt; not exactly sure why it does not build, but posting here for initial feedback (and possibly help with the build issue!)
Review of attachment 362942 [details] [review]: ::: gio/gfile.h @@ +609,3 @@ +GLIB_AVAILABLE_IN_2_56 +GFile * g_file_new_build_filename (const gchar *first_element, + ...); Wants G_GNUC_NULL_TERMINATED.
Created attachment 362987 [details] [review] gfileutils: factor out g_build_filename_va() This will be used in a later commit.
Created attachment 362988 [details] [review] gfile: add g_file_new_build_filename() This is a convenience C API that combines g_build_filename() with g_file_new_for_path().
Review of attachment 362987 [details] [review]: Sure.
Review of attachment 362988 [details] [review]: I’m not so happy about needing to expose g_build_filename_va() as a private function between GLib and GIO. Could we add a proper g_build_filename_va(const gchar *first_argument, va_list args) which is public, and use that instead? ::: gio/gfile.c @@ +6464,3 @@ + gchar *str; + GFile *file; + va_list args; Needs g_return_val_if_fail (first_element != NULL, NULL); ::: gio/tests/file.c @@ +45,1 @@ + file = g_file_new_build_filename (".", "some", "directory", "testfile", NULL); Should probably also include a test where there’s just the first element in the filename, and the NULL terminator. i.e. g_file_new_build_filename ("testfile", NULL);
Created attachment 363088 [details] [review] gfileutils: factor out g_build_filename_va() This will be used in a later commit.
Created attachment 363089 [details] [review] glib: add g_build_filename_valist() A new public API convenience to build a filename from a va_list.
Created attachment 363090 [details] [review] gfile: add g_file_new_build_filename() This is a convenience C API that combines g_build_filename() with g_file_new_for_path().
Updated the patchset to make g_build_filename_valist() also available and public.
Review of attachment 363088 [details] [review]: Yup.
Review of attachment 363089 [details] [review]: Yes.
Review of attachment 363090 [details] [review]: For sure.
Attachment 363088 [details] pushed as 68d62c3 - gfileutils: factor out g_build_filename_va() Attachment 363089 [details] pushed as 374ade1 - glib: add g_build_filename_valist() Attachment 363090 [details] pushed as 44d6052 - gfile: add g_file_new_build_filename()