From ae78cec9c78f3cb24d8212846be4eccc44a0108b Mon Sep 17 00:00:00 2001 From: Venkatesh Srinivas Date: Fri, 24 Feb 2012 10:22:37 -0800 Subject: [PATCH] libc -- stdlib: Implement aligned_alloc from C11. --- include/stdlib.h | 5 +++-- lib/libc/stdlib/Makefile.inc | 3 ++- lib/libc/stdlib/aligned_alloc.c | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 lib/libc/stdlib/aligned_alloc.c diff --git a/include/stdlib.h b/include/stdlib.h index 44b149a7cb..be88f6d099 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -289,8 +289,9 @@ long long /* * C11 functions. */ -int at_quick_exit(void (*func)(void)); -void quick_exit(int); +int at_quick_exit(void (*func)(void)); +void quick_exit(int); +void *aligned_alloc(size_t, size_t); /* Deprecated interfaces. */ #if !defined(_KERNEL_VIRTUAL) diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc index 64d9a53638..39ec4539ab 100644 --- a/lib/libc/stdlib/Makefile.inc +++ b/lib/libc/stdlib/Makefile.inc @@ -4,7 +4,8 @@ # machine-independent stdlib sources .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/stdlib ${.CURDIR}/../libc/stdlib -MISRCS+=a64l.c abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c \ +MISRCS+=a64l.c abort.c abs.c atexit.c aligned_alloc.c \ + atof.c atoi.c atol.c atoll.c \ bsearch.c div.c exit.c getenv.c getopt.c getopt_long.c \ getsubopt.c hcreate.c heapsort.c imaxabs.c imaxdiv.c \ insque.c l64a.c labs.c ldiv.c llabs.c lldiv.c lsearch.c \ diff --git a/lib/libc/stdlib/aligned_alloc.c b/lib/libc/stdlib/aligned_alloc.c new file mode 100644 index 0000000000..a5e7d48698 --- /dev/null +++ b/lib/libc/stdlib/aligned_alloc.c @@ -0,0 +1,17 @@ +#include +#include +#include + +void * +aligned_alloc(size_t alignment, size_t size) +{ + void *ptr; + int rc; + + ptr = NULL; + rc = posix_memalign(&ptr, alignment, size); + if (rc) + errno = rc; + + return (ptr); +} -- 2.41.0