mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-08 10:54:41 +00:00
Add fu_common_get_contents_stream() for future usage
This commit is contained in:
parent
52fd89f9ab
commit
bcf000d7cc
@ -281,14 +281,45 @@ GBytes *
|
|||||||
fu_common_get_contents_fd(gint fd, gsize count, GError **error)
|
fu_common_get_contents_fd(gint fd, gsize count, GError **error)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GIO_UNIX
|
#ifdef HAVE_GIO_UNIX
|
||||||
guint8 tmp[0x8000] = {0x0};
|
|
||||||
g_autoptr(GByteArray) buf = g_byte_array_new();
|
|
||||||
g_autoptr(GError) error_local = NULL;
|
|
||||||
g_autoptr(GInputStream) stream = NULL;
|
g_autoptr(GInputStream) stream = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail(fd > 0, NULL);
|
g_return_val_if_fail(fd > 0, NULL);
|
||||||
g_return_val_if_fail(error == NULL || *error == NULL, NULL);
|
g_return_val_if_fail(error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
|
/* read the entire fd to a data blob */
|
||||||
|
stream = g_unix_input_stream_new(fd, TRUE);
|
||||||
|
return fu_common_get_contents_stream(stream, count, error);
|
||||||
|
#else
|
||||||
|
g_set_error_literal(error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_NOT_SUPPORTED,
|
||||||
|
"Not supported as <glib-unix.h> is unavailable");
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_common_get_contents_stream:
|
||||||
|
* @stream: input stream
|
||||||
|
* @count: the maximum number of bytes to read
|
||||||
|
* @error: (nullable): optional return location for an error
|
||||||
|
*
|
||||||
|
* Reads a blob from a specific input stream.
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): a #GBytes, or %NULL
|
||||||
|
*
|
||||||
|
* Since: 1.7.4
|
||||||
|
**/
|
||||||
|
GBytes *
|
||||||
|
fu_common_get_contents_stream(GInputStream *stream, gsize count, GError **error)
|
||||||
|
{
|
||||||
|
guint8 tmp[0x8000] = {0x0};
|
||||||
|
g_autoptr(GByteArray) buf = g_byte_array_new();
|
||||||
|
g_autoptr(GError) error_local = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail(G_IS_INPUT_STREAM(stream), NULL);
|
||||||
|
g_return_val_if_fail(error == NULL || *error == NULL, NULL);
|
||||||
|
|
||||||
/* this is invalid */
|
/* this is invalid */
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
g_set_error_literal(error,
|
g_set_error_literal(error,
|
||||||
@ -298,9 +329,6 @@ fu_common_get_contents_fd(gint fd, gsize count, GError **error)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read the entire fd to a data blob */
|
|
||||||
stream = g_unix_input_stream_new(fd, TRUE);
|
|
||||||
|
|
||||||
/* read from stream in 32kB chunks */
|
/* read from stream in 32kB chunks */
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
gssize sz;
|
gssize sz;
|
||||||
@ -326,13 +354,6 @@ fu_common_get_contents_fd(gint fd, gsize count, GError **error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return g_byte_array_free_to_bytes(g_steal_pointer(&buf));
|
return g_byte_array_free_to_bytes(g_steal_pointer(&buf));
|
||||||
#else
|
|
||||||
g_set_error_literal(error,
|
|
||||||
FWUPD_ERROR,
|
|
||||||
FWUPD_ERROR_NOT_SUPPORTED,
|
|
||||||
"Not supported as <glib-unix.h> is unavailable");
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBARCHIVE
|
#ifdef HAVE_LIBARCHIVE
|
||||||
|
@ -201,6 +201,10 @@ fu_common_set_contents_bytes(const gchar *filename,
|
|||||||
GBytes *
|
GBytes *
|
||||||
fu_common_get_contents_bytes(const gchar *filename, GError **error) G_GNUC_WARN_UNUSED_RESULT;
|
fu_common_get_contents_bytes(const gchar *filename, GError **error) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
GBytes *
|
GBytes *
|
||||||
|
fu_common_get_contents_stream(GInputStream *stream,
|
||||||
|
gsize count,
|
||||||
|
GError **error) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
GBytes *
|
||||||
fu_common_get_contents_fd(gint fd, gsize count, GError **error) G_GNUC_WARN_UNUSED_RESULT;
|
fu_common_get_contents_fd(gint fd, gsize count, GError **error) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
gboolean
|
gboolean
|
||||||
fu_common_extract_archive(GBytes *blob, const gchar *dir, GError **error) G_GNUC_WARN_UNUSED_RESULT;
|
fu_common_extract_archive(GBytes *blob, const gchar *dir, GError **error) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
@ -980,6 +980,7 @@ LIBFWUPDPLUGIN_1.7.3 {
|
|||||||
|
|
||||||
LIBFWUPDPLUGIN_1.7.4 {
|
LIBFWUPDPLUGIN_1.7.4 {
|
||||||
global:
|
global:
|
||||||
|
fu_common_get_contents_stream;
|
||||||
fu_memmem_safe;
|
fu_memmem_safe;
|
||||||
local: *;
|
local: *;
|
||||||
} LIBFWUPDPLUGIN_1.7.3;
|
} LIBFWUPDPLUGIN_1.7.3;
|
||||||
|
Loading…
Reference in New Issue
Block a user