From: Jens Gustedt <Jens.Gustedt@inria.fr>
To: musl@lists.openwall.com
Subject: [musl] [C23 new stdlib 2/3] C23: add the memalignment function
Date: Wed, 31 May 2023 12:05:16 +0200 [thread overview]
Message-ID: <0620da4a3eaadc604c8e7696d81f5c44dfcac6fb.1685527375.git.Jens.Gustedt@inria.fr> (raw)
In-Reply-To: <cover.1685527375.git.Jens.Gustedt@inria.fr>
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
next prev parent reply other threads:[~2023-05-31 10:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-31 10:05 [musl] [C23 new stdlib 0/3] Jens Gustedt
2023-05-31 10:05 ` [musl] [C23 new stdlib 1/3] C23: add the new interfaces free_sized and free_aligned_sized for stdlib.h Jens Gustedt
2023-05-31 10:05 ` Jens Gustedt [this message]
2023-05-31 10:05 ` [musl] [C23 new stdlib 3/3] C23: implement the new strfrom[dfl] functions Jens Gustedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0620da4a3eaadc604c8e7696d81f5c44dfcac6fb.1685527375.git.Jens.Gustedt@inria.fr \
--to=jens.gustedt@inria.fr \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).