libotutil: Add API to create an "ay" GVariant from GBytes
We used to have a version of this, but since I'm trying to use
GBytes more, this became a more common operation, and it's annoying
to type out the whole G_VARIANT_TYPE ("ay") each time, and pass
TRUE for trusted.
https://bugzilla.gnome.org/show_bug.cgi?id=706031
This commit is contained in:
parent
71f6f10cd2
commit
76cd7ae4ea
|
|
@ -182,6 +182,7 @@ read_xattr_name_array (const char *path,
|
||||||
{
|
{
|
||||||
ssize_t bytes_read;
|
ssize_t bytes_read;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
gs_unref_bytes GBytes *bytes = NULL;
|
||||||
|
|
||||||
bytes_read = lgetxattr (path, p, NULL, 0);
|
bytes_read = lgetxattr (path, p, NULL, 0);
|
||||||
if (bytes_read < 0)
|
if (bytes_read < 0)
|
||||||
|
|
@ -194,18 +195,17 @@ read_xattr_name_array (const char *path,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
buf = g_malloc (bytes_read);
|
buf = g_malloc (bytes_read);
|
||||||
|
bytes = g_bytes_new_take (buf, bytes_read);
|
||||||
if (lgetxattr (path, p, buf, bytes_read) < 0)
|
if (lgetxattr (path, p, buf, bytes_read) < 0)
|
||||||
{
|
{
|
||||||
ot_util_set_error_from_errno (error, errno);
|
ot_util_set_error_from_errno (error, errno);
|
||||||
g_prefix_error (error, "lgetxattr (%s, %s) failed: ", path, p);
|
g_prefix_error (error, "lgetxattr (%s, %s) failed: ", path, p);
|
||||||
g_free (buf);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_variant_builder_add (builder, "(@ay@ay)",
|
g_variant_builder_add (builder, "(@ay@ay)",
|
||||||
g_variant_new_bytestring (p),
|
g_variant_new_bytestring (p),
|
||||||
g_variant_new_from_data (G_VARIANT_TYPE ("ay"),
|
ot_gvariant_new_ay_bytes (bytes));
|
||||||
buf, bytes_read, FALSE, g_free, buf));
|
|
||||||
|
|
||||||
p = p + strlen (p) + 1;
|
p = p + strlen (p) + 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,12 @@ ot_gvariant_new_bytearray (const guchar *data,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GVariant *
|
||||||
|
ot_gvariant_new_ay_bytes (GBytes *bytes)
|
||||||
|
{
|
||||||
|
return g_variant_new_from_bytes (G_VARIANT_TYPE ("ay"), bytes, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
GHashTable *
|
GHashTable *
|
||||||
ot_util_variant_asv_to_hash_table (GVariant *variant)
|
ot_util_variant_asv_to_hash_table (GVariant *variant)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ G_BEGIN_DECLS
|
||||||
GVariant *ot_gvariant_new_bytearray (const guchar *data,
|
GVariant *ot_gvariant_new_bytearray (const guchar *data,
|
||||||
gsize len);
|
gsize len);
|
||||||
|
|
||||||
|
GVariant *ot_gvariant_new_ay_bytes (GBytes *bytes);
|
||||||
|
|
||||||
GHashTable *ot_util_variant_asv_to_hash_table (GVariant *variant);
|
GHashTable *ot_util_variant_asv_to_hash_table (GVariant *variant);
|
||||||
|
|
||||||
GVariant * ot_util_variant_take_ref (GVariant *variant);
|
GVariant * ot_util_variant_take_ref (GVariant *variant);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue