summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-04-27 12:33:47 +0200
committerAlexander Larsson <alexl@redhat.com>2016-04-27 12:33:47 +0200
commitb8b3d319d4daa230a00e76e3ae46fd4d5a79b843 (patch)
treeab0bc994106e8a749d7e35868003fc8c61056a96 /common
parent74c06898435e566df0ea3346fac07e6fd28e5a51 (diff)
downloadxdg-app-b8b3d319d4daa230a00e76e3ae46fd4d5a79b843.tar.gz
common: Add xdg_app_variant_save
Diffstat (limited to 'common')
-rw-r--r--common/xdg-app-utils.c30
-rw-r--r--common/xdg-app-utils.h4
2 files changed, 34 insertions, 0 deletions
diff --git a/common/xdg-app-utils.c b/common/xdg-app-utils.c
index c750743..46906ce 100644
--- a/common/xdg-app-utils.c
+++ b/common/xdg-app-utils.c
@@ -1368,6 +1368,36 @@ xdg_app_cp_a (GFile *src,
}
gboolean
+xdg_app_variant_save (GFile *dest,
+ GVariant *variant,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(GOutputStream) out = NULL;
+ gsize bytes_written;
+
+ out = (GOutputStream*)g_file_replace (dest, NULL, FALSE,
+ G_FILE_CREATE_REPLACE_DESTINATION,
+ cancellable, error);
+ if (out == NULL)
+ return FALSE;
+
+ if (!g_output_stream_write_all (out,
+ g_variant_get_data (variant),
+ g_variant_get_size (variant),
+ &bytes_written,
+ cancellable,
+ error))
+ return FALSE;
+
+ if (!g_output_stream_close (out, cancellable, error))
+ return FALSE;
+
+ return TRUE;
+}
+
+
+gboolean
xdg_app_variant_bsearch_str (GVariant *array,
const char *str,
int *out_pos)
diff --git a/common/xdg-app-utils.h b/common/xdg-app-utils.h
index 0e6b9e8..9b5e7c0 100644
--- a/common/xdg-app-utils.h
+++ b/common/xdg-app-utils.h
@@ -45,6 +45,10 @@ GBytes * xdg_app_read_stream (GInputStream *in,
gboolean null_terminate,
GError **error);
+gboolean xdg_app_variant_save (GFile *dest,
+ GVariant *variant,
+ GCancellable *cancellable,
+ GError **error);
gboolean xdg_app_variant_bsearch_str (GVariant *array,
const char *str,
int *out_pos);