From 5580b93f367e057ef0184231e7619beea4ae3734 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 5 May 2021 08:46:24 +0200 Subject: libc: Reimplement posix_memlign() Move all error checks into posix_memalign() so that the returned memory pointer is set to NULL under all error conditions except memptr == NULL. Use parameter names of POSIX documentation. --- cpukit/libcsupport/src/posix_memalign.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'cpukit') diff --git a/cpukit/libcsupport/src/posix_memalign.c b/cpukit/libcsupport/src/posix_memalign.c index b2bef3e525..316ed7315c 100644 --- a/cpukit/libcsupport/src/posix_memalign.c +++ b/cpukit/libcsupport/src/posix_memalign.c @@ -24,18 +24,33 @@ #include int posix_memalign( - void **pointer, + void **memptr, size_t alignment, size_t size ) { - if (((alignment - 1) & alignment) != 0 || (alignment < sizeof(void *))) + RTEMS_OBFUSCATE_VARIABLE( memptr ); + + if ( memptr == NULL ) { + return EINVAL; + } + + *memptr = NULL; + + if ( alignment < sizeof( void * ) ) { return EINVAL; + } + + if ( ( ( alignment - 1 ) & alignment ) != 0 ) { + return EINVAL; + } + + *memptr = rtems_heap_allocate_aligned_with_boundary( size, alignment, 0 ); + + if ( *memptr == NULL ) { + return ENOMEM; + } - /* - * rtems_memalign does all of the error checking work EXCEPT - * for adding restrictionso on the alignment. - */ - return rtems_memalign( pointer, alignment, size ); + return 0; } #endif -- cgit v1.2.3