summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/malloc.c
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2012-01-09 06:36:28 +0000
committered <ed@FreeBSD.org>2012-01-09 06:36:28 +0000
commit990fc2900cc85359139fbca95c216c6c302873af (patch)
tree95b1629eb692f9ea1ee495c472e77e7e68422189 /lib/libc/stdlib/malloc.c
parentb9d5a50095d3b8b3b530da7e7b24d476068d01b5 (diff)
downloadFreeBSD-src-990fc2900cc85359139fbca95c216c6c302873af.zip
FreeBSD-src-990fc2900cc85359139fbca95c216c6c302873af.tar.gz
Add aligned_alloc(3).
The C11 folks reinvented the wheel by introducing an aligned version of malloc(3) called aligned_alloc(3), instead of posix_memalign(3). Instead of returning the allocation by reference, it returns the address, just like malloc(3). Reviewed by: jasone@
Diffstat (limited to 'lib/libc/stdlib/malloc.c')
-rw-r--r--lib/libc/stdlib/malloc.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index 7ef59e4..2d932cb 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/lib/libc/stdlib/malloc.c
@@ -6043,6 +6043,20 @@ RETURN:
}
void *
+aligned_alloc(size_t alignment, size_t size)
+{
+ void *memptr;
+ int ret;
+
+ ret = posix_memalign(&memptr, alignment, size);
+ if (ret != 0) {
+ errno = ret;
+ return (NULL);
+ }
+ return (memptr);
+}
+
+void *
calloc(size_t num, size_t size)
{
void *ret;
OpenPOWER on IntegriCloud