summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-05-05 08:46:24 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-05-06 08:03:58 +0200
commit5580b93f367e057ef0184231e7619beea4ae3734 (patch)
tree8dd102d88af6e15666a72d1708508b9195665bc4 /cpukit
parent48898b3a5d27a73a65f2b7520ceb53005d45c984 (diff)
downloadrtems-5580b93f367e057ef0184231e7619beea4ae3734.tar.bz2
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.
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/libcsupport/src/posix_memalign.c29
1 files changed, 22 insertions, 7 deletions
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 <errno.h>
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