[glib/wip/gvariant-kdbus: 5/17] GBytes: add g_bytes_get_zero_copy_fd()
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gvariant-kdbus: 5/17] GBytes: add g_bytes_get_zero_copy_fd()
- Date: Wed, 3 Dec 2014 07:17:00 +0000 (UTC)
commit f2437b7f1c3fd1d4c5bd6c01ed26d7a876992eea
Author: Ryan Lortie <desrt desrt ca>
Date: Tue Dec 2 14:29:04 2014 -0500
GBytes: add g_bytes_get_zero_copy_fd()
Add a way to get the zero-copy fd back out of a GBytes that was created
from one.
docs/reference/glib/glib-sections.txt | 1 +
glib/gbytes.c | 29 +++++++++++++++++++++++++++++
glib/gbytes.h | 3 +++
3 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 49ea6e5..d13a5ae 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -2479,6 +2479,7 @@ g_bytes_new_with_free_func
g_bytes_new_from_bytes
g_bytes_get_data
g_bytes_get_size
+g_bytes_get_zero_copy_fd
g_bytes_hash
g_bytes_equal
g_bytes_compare
diff --git a/glib/gbytes.c b/glib/gbytes.c
index 27f56eb..266e257 100644
--- a/glib/gbytes.c
+++ b/glib/gbytes.c
@@ -406,6 +406,35 @@ g_bytes_get_size (GBytes *bytes)
return bytes->size;
}
+/**
+ * g_bytes_get_zero_copy_fd:
+ * @bytes: a #GBytes
+ *
+ * Gets the zero-copy fd from a #GBytes, if it has one.
+ *
+ * Returns -1 if @bytes was not created from a zero-copy fd.
+ *
+ * A #GBytes created with a zero-copy fd may have been internally
+ * converted into another type of #GBytes for any reason at all. This
+ * function may therefore return -1 at any time, even for a #GBytes that
+ * was created with g_bytes_new_take_zero_copy_fd().
+ *
+ * The returned file descriptor belongs to @bytes. Do not close it.
+ *
+ * Returns: a file descriptor, or -1
+ *
+ * Since: 2.44
+ */
+gint
+g_bytes_get_zero_copy_fd (GBytes *bytes)
+{
+ g_return_val_if_fail (bytes != NULL, -1);
+
+ if (G_BYTES_IS_MEMFD (bytes))
+ return bytes->type_or_fd;
+ else
+ return -1;
+}
/**
* g_bytes_ref:
diff --git a/glib/gbytes.h b/glib/gbytes.h
index 459f95e..16f38aa 100644
--- a/glib/gbytes.h
+++ b/glib/gbytes.h
@@ -66,6 +66,9 @@ gconstpointer g_bytes_get_data (GBytes *bytes,
GLIB_AVAILABLE_IN_ALL
gsize g_bytes_get_size (GBytes *bytes);
+GLIB_AVAILABLE_IN_2_44
+gint g_bytes_get_zero_copy_fd (GBytes *bytes);
+
GLIB_AVAILABLE_IN_ALL
GBytes * g_bytes_ref (GBytes *bytes);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]