Even though Korli beat me, I've updated the posix_memalign() function to be more standards

compliant:
* it now checks the alignment is a multiple of 4 (needs to be changed for 64 bit architectures)
* it no longer sets errno.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21975 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-08-16 10:04:44 +00:00
parent bf7beb500c
commit dfd5242e7f
2 changed files with 23 additions and 13 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2006, Haiku Inc. All Rights Reserved.
* Copyright 2002-2007, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _STDLIB_H_
@ -45,11 +45,11 @@ extern "C" {
#endif
/* memory allocation (see malloc.h for additional defines & prototypes) */
extern void *calloc(size_t nmemb, size_t size);
extern void *calloc(size_t numElements, size_t size);
extern void free(void *pointer);
extern void *malloc(size_t size);
extern void *realloc(void * ptr, size_t size);
extern int posix_memalign(void **memptr, size_t alignment, size_t size);
extern int posix_memalign(void **_pointer, size_t alignment, size_t size);
extern void *realloc(void *oldPointer, size_t newSize);
/* process termination */
extern void abort(void);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2006, Haiku Inc.
* Copyright 2002-2007, Haiku Inc.
* Distributed under the terms of the MIT License.
*/
@ -260,7 +260,8 @@ extern "C" void *
memalign(size_t alignment, size_t size)
{
static processHeap *pHeap = getAllocator();
void *addr = pHeap->getHeap(pHeap->getHeapIndex()).memalign(alignment, size);
void *addr = pHeap->getHeap(pHeap->getHeapIndex()).memalign(alignment,
size);
if (addr == NULL) {
errno = B_NO_MEMORY;
return NULL;
@ -275,14 +276,23 @@ memalign(size_t alignment, size_t size)
extern "C" int
posix_memalign(void **memptr, size_t alignment, size_t size)
posix_memalign(void **_pointer, size_t alignment, size_t size)
{
if (!memptr)
return EINVAL;
*memptr = memalign(alignment, size);
if (memptr == NULL)
return ENOMEM;
return 0;
if ((alignment & 3) != 0 || _pointer == NULL)
return B_BAD_VALUE;
static processHeap *pHeap = getAllocator();
void *pointer = pHeap->getHeap(pHeap->getHeapIndex()).memalign(alignment,
size);
if (pointer == NULL)
return NULL;
#if HEAP_LEAK_CHECK
add_address(pointer, size);
#endif
*_pointer = pointer;
return 0;
}