[glib/gsettings: 249/327] Add g_variant_from_file
- From: Ryan Lortie <ryanl src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glib/gsettings: 249/327] Add g_variant_from_file
- Date: Thu, 27 Aug 2009 17:48:52 +0000 (UTC)
commit e813908228799f5c63c835ab73f1d7db664ea256
Author: Ryan Lortie <desrt desrt ca>
Date: Mon Jun 29 18:31:29 2009 -0400
Add g_variant_from_file
- combine g_mapped_file_new with g_variant_from_data
docs/reference/glib/glib-sections.txt | 1 +
glib/glib.symbols | 3 ++
glib/gvariant-loadstore.h | 42 ++++++++++++++++++---------------
glib/gvariant-util.c | 36 ++++++++++++++++++++++++++++
4 files changed, 63 insertions(+), 19 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 6ab7ebb..82847f9 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -2855,6 +2855,7 @@ g_variant_load
g_variant_store
g_variant_flatten
g_variant_from_data
+g_variant_from_file
g_variant_from_slice
g_variant_get_data
g_variant_get_size
diff --git a/glib/glib.symbols b/glib/glib.symbols
index 5b47bfb..35151b7 100644
--- a/glib/glib.symbols
+++ b/glib/glib.symbols
@@ -1794,6 +1794,9 @@ g_variant_store
g_variant_get_data
g_variant_get_size
#endif
+#if IN_FILE(_gvariant_util_c_)
+g_variant_from_file
+#endif
#endif
#if IN_HEADER(_gvariant_private_h_)
diff --git a/glib/gvariant-loadstore.h b/glib/gvariant-loadstore.h
index 7032fd7..0559fb2 100644
--- a/glib/gvariant-loadstore.h
+++ b/glib/gvariant-loadstore.h
@@ -21,25 +21,29 @@ typedef enum
G_BEGIN_DECLS
-GVariant *g_variant_load (const GVariantType *type,
- gconstpointer data,
- gsize size,
- GVariantFlags flags);
-GVariant *g_variant_from_slice (const GVariantType *type,
- gpointer slice,
- gsize size,
- GVariantFlags flags);
-GVariant *g_variant_from_data (const GVariantType *type,
- gconstpointer data,
- gsize size,
- GVariantFlags flags,
- GDestroyNotify notify,
- gpointer user_data);
-
-void g_variant_store (GVariant *value,
- gpointer data);
-gconstpointer g_variant_get_data (GVariant *value);
-gsize g_variant_get_size (GVariant *value);
+GVariant *g_variant_load (const GVariantType *type,
+ gconstpointer data,
+ gsize size,
+ GVariantFlags flags);
+GVariant *g_variant_from_slice (const GVariantType *type,
+ gpointer slice,
+ gsize size,
+ GVariantFlags flags);
+GVariant *g_variant_from_data (const GVariantType *type,
+ gconstpointer data,
+ gsize size,
+ GVariantFlags flags,
+ GDestroyNotify notify,
+ gpointer user_data);
+GVariant *g_variant_from_file (const GVariantType *type,
+ const gchar *filename,
+ GVariantFlags flags,
+ GError **error);
+
+void g_variant_store (GVariant *value,
+ gpointer data);
+gconstpointer g_variant_get_data (GVariant *value);
+gsize g_variant_get_size (GVariant *value);
G_END_DECLS
diff --git a/glib/gvariant-util.c b/glib/gvariant-util.c
index 3b4e224..44f511c 100644
--- a/glib/gvariant-util.c
+++ b/glib/gvariant-util.c
@@ -1918,5 +1918,41 @@ g_variant_lookup_value (GVariant *dictionary,
return result;
}
+/**
+ * g_variant_from_file:
+ * @type: the #GVariantType of the new variant
+ * @filename: the filename to load from
+ * @flags: zero or more #GVariantFlags
+ * @error: a pointer to a #GError, or %NULL
+ * @returns: a new #GVariant instance, or %NULL
+ *
+ * Utility function to load a #GVariant from the contents of a file,
+ * using a #GMappedFile.
+ *
+ * This function attempts to open @filename using #GMappedFile and then
+ * calls g_variant_from_data() on the result. As with that function,
+ * @type may be %NULL.
+ **/
+GVariant *
+g_variant_from_file (const GVariantType *type,
+ const gchar *filename,
+ GVariantFlags flags,
+ GError **error)
+{
+ GMappedFile *mapped;
+
+ mapped = g_mapped_file_new (filename, FALSE, error);
+
+ if (mapped == NULL)
+ return NULL;
+
+ return g_variant_from_data (type,
+ g_mapped_file_get_contents (mapped),
+ g_mapped_file_get_length (mapped),
+ flags,
+ (GDestroyNotify) g_mapped_file_unref,
+ mapped);
+}
+
#define _gvariant_util_c_
#include "galiasdef.c"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]