summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/compat.c26
-rw-r--r--src/common/compat.h2
2 files changed, 26 insertions, 2 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 23efe0b656..8fd6d9bc15 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -449,8 +449,21 @@ get_uint32(const char *cp)
return v;
}
/**
+ * Read a 32-bit value beginning at <b>cp</b>. Equivalent to
+ * *(uint32_t*)(cp), but will not cause segfaults on platforms that forbid
+ * unaligned memory access.
+ */
+uint64_t
+get_uint64(const char *cp)
+{
+ uint64_t v;
+ memcpy(&v,cp,8);
+ return v;
+}
+
+/**
* Set a 16-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to
- * *(uint16_t)(cp) = v, but will not cause segfaults on platforms that forbid
+ * *(uint16_t*)(cp) = v, but will not cause segfaults on platforms that forbid
* unaligned memory access. */
void
set_uint16(char *cp, uint16_t v)
@@ -459,13 +472,22 @@ set_uint16(char *cp, uint16_t v)
}
/**
* Set a 32-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to
- * *(uint32_t)(cp) = v, but will not cause segfaults on platforms that forbid
+ * *(uint32_t*)(cp) = v, but will not cause segfaults on platforms that forbid
* unaligned memory access. */
void
set_uint32(char *cp, uint32_t v)
{
memcpy(cp,&v,4);
}
+/**
+ * Set a 64-bit value beginning at <b>cp</b> to <b>v</b>. Equivalent to
+ * *(uint64_t*)(cp) = v, but will not cause segfaults on platforms that forbid
+ * unaligned memory access. */
+void
+set_uint64(char *cp, uint64_t v)
+{
+ memcpy(cp,&v,8);
+}
/**
* Rename the file <b>from</b> to the file <b>to</b>. On unix, this is
diff --git a/src/common/compat.h b/src/common/compat.h
index 7e8c83a297..b80bdd1222 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -450,8 +450,10 @@ const char *get_uname(void);
uint16_t get_uint16(const char *cp) ATTR_PURE ATTR_NONNULL((1));
uint32_t get_uint32(const char *cp) ATTR_PURE ATTR_NONNULL((1));
+uint64_t get_uint64(const char *cp) ATTR_PURE ATTR_NONNULL((1));
void set_uint16(char *cp, uint16_t v) ATTR_NONNULL((1));
void set_uint32(char *cp, uint32_t v) ATTR_NONNULL((1));
+void set_uint64(char *cp, uint64_t v) ATTR_NONNULL((1));
/* These uint8 variants are defined to make the code more uniform. */
#define get_uint8(cp) (*(const uint8_t*)(cp))