aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/db/mpool/mpool.c2
-rw-r--r--lib/libc/stdlib/Makefile.inc4
-rw-r--r--lib/libc/stdlib/Symbol.map1
-rw-r--r--lib/libc/stdlib/exit.32
-rw-r--r--lib/libc/stdlib/memalignment.353
-rw-r--r--lib/libc/stdlib/memalignment.c28
6 files changed, 86 insertions, 4 deletions
diff --git a/lib/libc/db/mpool/mpool.c b/lib/libc/db/mpool/mpool.c
index 9dab032134bc..1bab66d73baf 100644
--- a/lib/libc/db/mpool/mpool.c
+++ b/lib/libc/db/mpool/mpool.c
@@ -455,7 +455,7 @@ mpool_stat(MPOOL *mp)
(void)fprintf(stderr, "%lu pages in the file\n", mp->npages);
(void)fprintf(stderr,
- "page size %lu, cacheing %lu pages of %lu page max cache\n",
+ "page size %lu, caching %lu pages of %lu page max cache\n",
mp->pagesize, mp->curcache, mp->maxcache);
(void)fprintf(stderr, "%lu page puts, %lu page gets, %lu page new\n",
mp->pageput, mp->pageget, mp->pagenew);
diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc
index e7b9955b9646..b878a7625e9f 100644
--- a/lib/libc/stdlib/Makefile.inc
+++ b/lib/libc/stdlib/Makefile.inc
@@ -7,7 +7,7 @@ MISRCS+=C99_Exit.c a64l.c abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c \
div.c exit.c getenv.c getopt.c getopt_long.c \
getsubopt.c hcreate.c hcreate_r.c hdestroy_r.c heapsort.c heapsort_b.c \
hsearch_r.c imaxabs.c imaxdiv.c \
- insque.c l64a.c labs.c ldiv.c llabs.c lldiv.c lsearch.c \
+ insque.c l64a.c labs.c ldiv.c llabs.c lldiv.c lsearch.c memalignment.c \
merge.c mergesort_b.c ptsname.c qsort.c qsort_r.c qsort_r_compat.c \
qsort_s.c quick_exit.c radixsort.c rand.c \
random.c reallocarray.c reallocf.c realpath.c recallocarray.c remque.c \
@@ -35,7 +35,7 @@ MAN+= a64l.3 abort.3 abs.3 atexit.3 atof.3 \
atoi.3 atol.3 at_quick_exit.3 bsearch.3 \
div.3 exit.3 getenv.3 getopt.3 getopt_long.3 getsubopt.3 \
hcreate.3 imaxabs.3 imaxdiv.3 insque.3 labs.3 ldiv.3 llabs.3 lldiv.3 \
- lsearch.3 memory.3 ptsname.3 qsort.3 \
+ lsearch.3 memalignment.3 memory.3 ptsname.3 qsort.3 \
quick_exit.3 \
radixsort.3 rand.3 random.3 reallocarray.3 reallocf.3 realpath.3 \
set_constraint_handler_s.3 \
diff --git a/lib/libc/stdlib/Symbol.map b/lib/libc/stdlib/Symbol.map
index 53d71bcafb7d..8b7e97c3cbdc 100644
--- a/lib/libc/stdlib/Symbol.map
+++ b/lib/libc/stdlib/Symbol.map
@@ -132,6 +132,7 @@ FBSD_1.8 {
};
FBSD_1.9 {
+ memalignment;
recallocarray;
};
diff --git a/lib/libc/stdlib/exit.3 b/lib/libc/stdlib/exit.3
index bfb14c5c9f83..40010e678e5f 100644
--- a/lib/libc/stdlib/exit.3
+++ b/lib/libc/stdlib/exit.3
@@ -104,7 +104,7 @@ may be used to provide more information to the parent process.
.Pp
The complete
.Fa status
-value is avaliable as
+value is available as
.Va si_status
member of the
.Vt siginfo_t
diff --git a/lib/libc/stdlib/memalignment.3 b/lib/libc/stdlib/memalignment.3
new file mode 100644
index 000000000000..4a2269a82c81
--- /dev/null
+++ b/lib/libc/stdlib/memalignment.3
@@ -0,0 +1,53 @@
+.\"
+.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd November 10, 2025
+.Dt MEMALIGNMENT 3
+.Os
+.Sh NAME
+.Nm memalignment
+.Nd find the memory alignment of an object
+.Sh SYNOPSIS
+.Lb libc
+.In stdlib.h
+.Ft size_t
+.Fn memalignment "const void *ptr"
+.Sh DESCRIPTION
+The
+.Fn memalignment
+function determines the alignment of the object pointed to by
+.Fa ptr .
+This alignment is a power of\~2, and may be larger than the range
+supported by the
+.Sy alignof
+operator.
+The value returned can be compared to the result of
+.Sy alignof ,
+and if it is greater or equal, the alignment requirement of the operand
+is satisfied.
+.Sh RETURN VALUES
+Returns the alignment of
+.Fa ptr
+as a power of\~2.
+If
+.Fa ptr
+is a null pointer, an alignment of zero is returned.
+An alignment of zero indicates that the tested pointer cannot be used to
+access an object of any type.
+.Sh SEE ALSO
+.Xr aligned_alloc 3 ,
+.Xr posix_memalign 3
+.Sh STANDARDS
+The
+.Fn memalignment
+function conforms to
+.St -isoC-2023 .
+.Sh HISTORY
+The
+.Fn memalignment
+function was added in
+.Fx 15.1.
+.Sh AUTHOR
+.An Robert Clausecker Aq Mt fuz@FreeBSD.org
diff --git a/lib/libc/stdlib/memalignment.c b/lib/libc/stdlib/memalignment.c
new file mode 100644
index 000000000000..771ddc2f5253
--- /dev/null
+++ b/lib/libc/stdlib/memalignment.c
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+size_t
+memalignment(const void *p)
+{
+ uintptr_t align;
+
+ if (p == NULL)
+ return (0);
+
+ align = (uintptr_t)p;
+ align &= -align;
+
+#if UINTPTR_MAX > SIZE_MAX
+ /* if alignment overflows size_t, return maximum possible */
+ if (align > SIZE_MAX)
+ align = SIZE_MAX - SIZE_MAX/2;
+#endif
+
+ return (align);
+}