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:
parent
bf7beb500c
commit
dfd5242e7f
@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _STDLIB_H_
|
#ifndef _STDLIB_H_
|
||||||
@ -45,11 +45,11 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* memory allocation (see malloc.h for additional defines & prototypes) */
|
/* 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 free(void *pointer);
|
||||||
extern void *malloc(size_t size);
|
extern void *malloc(size_t size);
|
||||||
extern void *realloc(void * ptr, size_t size);
|
extern int posix_memalign(void **_pointer, size_t alignment, size_t size);
|
||||||
extern int posix_memalign(void **memptr, size_t alignment, size_t size);
|
extern void *realloc(void *oldPointer, size_t newSize);
|
||||||
|
|
||||||
/* process termination */
|
/* process termination */
|
||||||
extern void abort(void);
|
extern void abort(void);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2006, Haiku Inc.
|
* Copyright 2002-2007, Haiku Inc.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -260,7 +260,8 @@ extern "C" void *
|
|||||||
memalign(size_t alignment, size_t size)
|
memalign(size_t alignment, size_t size)
|
||||||
{
|
{
|
||||||
static processHeap *pHeap = getAllocator();
|
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) {
|
if (addr == NULL) {
|
||||||
errno = B_NO_MEMORY;
|
errno = B_NO_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -275,14 +276,23 @@ memalign(size_t alignment, size_t size)
|
|||||||
|
|
||||||
|
|
||||||
extern "C" int
|
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)
|
if ((alignment & 3) != 0 || _pointer == NULL)
|
||||||
return EINVAL;
|
return B_BAD_VALUE;
|
||||||
*memptr = memalign(alignment, size);
|
|
||||||
if (memptr == NULL)
|
static processHeap *pHeap = getAllocator();
|
||||||
return ENOMEM;
|
void *pointer = pHeap->getHeap(pHeap->getHeapIndex()).memalign(alignment,
|
||||||
return 0;
|
size);
|
||||||
|
if (pointer == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
#if HEAP_LEAK_CHECK
|
||||||
|
add_address(pointer, size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
*_pointer = pointer;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user