summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem.jover@nokia.com>2008-03-13 18:41:14 +0100
committerDanny Kukawka <danny.kukawka@web.de>2008-03-13 18:41:14 +0100
commit0e0938e87a16791322561897ad2ca2459fc3983e (patch)
treed02de4589fb24414ce8df4b70a5f49a0cd5420d1
parent07cfd3ad1e2fb4527ab46962dfef2244580e7903 (diff)
partutil: make the get endian functions alignment aware
On architectures where unaligned access is not supported, it might have to be fixed at runtime which can cause slow downs or make the code abort (like generating SIGBUS).
-rw-r--r--partutil/partutil.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/partutil/partutil.c b/partutil/partutil.c
index 35fc82d7..c623ca2e 100644
--- a/partutil/partutil.c
+++ b/partutil/partutil.c
@@ -146,27 +146,39 @@ part_table_find (PartitionTable *p, guint64 offset,
static guint16
get_le16 (const void *buf)
{
- return GUINT16_FROM_LE ( * ((guint16 *) buf) );
+ guint16 i;
+
+ memcpy (&i, buf, sizeof (i));
+ return GUINT16_FROM_LE (i);
}
static guint32
get_le32 (const void *buf)
{
- return GUINT32_FROM_LE ( * ((guint32 *) buf) );
+ guint32 i;
+
+ memcpy (&i, buf, sizeof (i));
+ return GUINT32_FROM_LE (i);
}
static guint64
get_le64 (const void *buf)
{
- return GUINT64_FROM_LE ( * ((guint64 *) buf) );
+ guint64 i;
+
+ memcpy (&i, buf, sizeof (i));
+ return GUINT64_FROM_LE (i);
}
static guint32
get_be32 (const void *buf)
{
- return GUINT32_FROM_BE ( * ((guint32 *) buf) );
+ guint32 i;
+
+ memcpy (&i, buf, sizeof (i));
+ return GUINT32_FROM_BE (i);
}
/* see http://en.wikipedia.org/wiki/Globally_Unique_Identifier - excerpt