mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-03 03:56:30 +00:00
trivial: Add helper function for parsing a uint4 buffer
This commit is contained in:
parent
b900c09ced
commit
b04a8778e9
@ -212,6 +212,26 @@ dfu_utils_bytes_is_empty (GBytes *bytes)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* dfu_utils_buffer_parse_uint4:
|
||||
* @data: a string
|
||||
*
|
||||
* Parses a base 16 number from a string.
|
||||
*
|
||||
* The string MUST be at least 1 byte long as this function cannot check the
|
||||
* length of @data. Checking the size must be done in the caller.
|
||||
*
|
||||
* Return value: A parsed value, or 0 for error
|
||||
**/
|
||||
guint8
|
||||
dfu_utils_buffer_parse_uint4 (const gchar *data)
|
||||
{
|
||||
gchar buffer[2];
|
||||
memcpy (buffer, data, 1);
|
||||
buffer[1] = '\0';
|
||||
return (guint8) g_ascii_strtoull (buffer, NULL, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* dfu_utils_buffer_parse_uint8:
|
||||
* @data: a string
|
||||
|
@ -173,6 +173,7 @@ const gchar *dfu_version_to_string (DfuVersion version);
|
||||
/* helpers */
|
||||
GBytes *dfu_utils_bytes_join_array (GPtrArray *chunks);
|
||||
gboolean dfu_utils_bytes_is_empty (GBytes *bytes);
|
||||
guint8 dfu_utils_buffer_parse_uint4 (const gchar *data);
|
||||
guint8 dfu_utils_buffer_parse_uint8 (const gchar *data);
|
||||
guint16 dfu_utils_buffer_parse_uint16 (const gchar *data);
|
||||
guint32 dfu_utils_buffer_parse_uint24 (const gchar *data);
|
||||
|
Loading…
Reference in New Issue
Block a user