38 lines
1.2 KiB
Diff
38 lines
1.2 KiB
Diff
From 68459714838c8c0c2d34b6d658638f5d59298bc7 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <thomas@t-8ch.de>
|
|
Date: Sun, 1 Oct 2023 13:57:12 +0200
|
|
Subject: [PATCH] include/c.h: add helpers for unaligned structure access
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
|
|
Reference:https://github.com/util-linux/util-linux/commit/68459714838c8c0c2d34b6d658638f5d59298bc7
|
|
Conflict:NA
|
|
---
|
|
include/c.h | 8 ++++++++
|
|
1 file changed, 8 insertions(+)
|
|
|
|
diff --git a/include/c.h b/include/c.h
|
|
index 752f568c5..224a8e54f 100644
|
|
--- a/include/c.h
|
|
+++ b/include/c.h
|
|
@@ -213,6 +213,14 @@
|
|
(type *)( (char *)__mptr - offsetof(type,member) );})
|
|
#endif
|
|
|
|
+#define read_unaligned_member(p, m) __extension__ ({ \
|
|
+ size_t offset = offsetof(__typeof__(* p), m); \
|
|
+ __typeof__(p->m) v; \
|
|
+ memcpy(&v, ((unsigned char *)p) + offset, sizeof(v)); \
|
|
+ v; })
|
|
+
|
|
+#define member_ptr(p, m) (((unsigned char *)p) + offsetof(__typeof__(*p), m))
|
|
+
|
|
#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
|
|
# ifdef HAVE___PROGNAME
|
|
extern char *__progname;
|
|
--
|
|
2.33.0
|
|
|