Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 31 May 2023 12:05:16 +0200
From: Jens Gustedt <Jens.Gustedt@...ia.fr>
To: musl@...ts.openwall.com
Subject: [C23 new stdlib 2/3] C23: add the memalignment function

The name is reserved, so we don't need to protect it via a feature
macro or a weak symbol.
---
 include/stdlib.h          | 2 ++
 src/stdlib/memalignment.c | 8 ++++++++
 2 files changed, 10 insertions(+)
 create mode 100644 src/stdlib/memalignment.c

diff --git a/include/stdlib.h b/include/stdlib.h
index 2f46e6aa..10bdf7f8 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -180,6 +180,8 @@ typedef int once_flag;
 void call_once(once_flag *, void (*)(void));
 #endif
 
+size_t memalignment(const void *);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/stdlib/memalignment.c b/src/stdlib/memalignment.c
new file mode 100644
index 00000000..0f87c71b
--- /dev/null
+++ b/src/stdlib/memalignment.c
@@ -0,0 +1,8 @@
+#include <stdlib.h>
+#include <stdint.h>
+
+size_t memalignment(const void *p)
+{
+	uintptr_t bits = (uintptr_t)p;
+	return (bits^(bits-1))&bits;
+}
-- 
2.34.1

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.