forked from Imagelibrary/rtems
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.
This commit is contained in:
@@ -24,18 +24,33 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
int posix_memalign(
|
int posix_memalign(
|
||||||
void **pointer,
|
void **memptr,
|
||||||
size_t alignment,
|
size_t alignment,
|
||||||
size_t size
|
size_t size
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (((alignment - 1) & alignment) != 0 || (alignment < sizeof(void *)))
|
RTEMS_OBFUSCATE_VARIABLE( memptr );
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
/*
|
if ( memptr == NULL ) {
|
||||||
* rtems_memalign does all of the error checking work EXCEPT
|
return EINVAL;
|
||||||
* for adding restrictionso on the alignment.
|
}
|
||||||
*/
|
|
||||||
return rtems_memalign( pointer, alignment, size );
|
*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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user