summaryrefslogtreecommitdiff
path: root/libappstream-glib/as-utils.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2015-10-09 12:14:54 +0100
committerRichard Hughes <richard@hughsie.com>2015-10-09 12:15:59 +0100
commit592a4c48d7e375ac3004192462d3a8947b076d20 (patch)
tree2de6c625c1c85c421465e0d4c61a0a7f16279e12 /libappstream-glib/as-utils.c
parent43267bebbca23f98959d328b4557adb54149c445 (diff)
downloadappstream-glib-592a4c48d7e375ac3004192462d3a8947b076d20.tar.gz
Switch to the Microsoft dotted-decimal version encoding
This is also being used by Intel for identifying UEFI capsules.
Diffstat (limited to 'libappstream-glib/as-utils.c')
-rw-r--r--libappstream-glib/as-utils.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c
index 339efa4..b7e218d 100644
--- a/libappstream-glib/as-utils.c
+++ b/libappstream-glib/as-utils.c
@@ -1667,7 +1667,8 @@ as_utils_guid_from_string (const gchar *str)
* as_utils_version_from_uint32:
* @val: A uint32le version number
*
- * Returns a dotted decimal version string from a 32 bit number.
+ * Returns a version string from a 32 bit LE number in the Microsoft-style
+ * AA.BB.CCDD dotted-decimal notation, with leading sections and zeros ignored.
*
* Returns: A version number, e.g. "1.0.3"
*
@@ -1677,17 +1678,19 @@ gchar *
as_utils_version_from_uint32 (guint32 val)
{
GString *str;
- gboolean valid = FALSE;
guint i;
- guint8 *tmp = (guint8 *) &val;
+ guint16 tmp[3];
+
+ /* create version string using the MS format */
+ tmp[0] = (val >> 24) & 0xff;
+ tmp[1] = (val >> 16) & 0xff;
+ tmp[2] = val & 0xffff;
/* create version string */
str = g_string_sized_new (13);
- for (i = 0; i < 4; i++) {
- if (tmp[3 - i] > 0 || i == 3)
- valid = TRUE;
- if (valid)
- g_string_append_printf (str, "%i.", tmp[3 - i]);
+ for (i = 0; i < 3; i++) {
+ if (i == 2 || tmp[i] > 0 || str->len > 0)
+ g_string_append_printf (str, "%i.", tmp[i]);
}
/* delete trailing dot */