Merge "Add the posix_memalign(3) function to bionic"

This commit is contained in:
Ken Sumrall 2011-12-20 15:06:52 -08:00 committed by Android (Google) Code Review
commit 334379dada
2 changed files with 30 additions and 0 deletions

View file

@ -773,6 +773,22 @@ void* dlrealloc(void*, size_t);
*/
void* dlmemalign(size_t, size_t);
/*
int posix_memalign(void **memptr, size_t alignment, size_t size);
Places a pointer to a newly allocated chunk of size bytes, aligned
in accord with the alignment argument, in *memptr.
The return value is 0 on success, and ENOMEM on failure.
The alignment argument should be a power of two. If the argument is
not a power of two, the nearest greater power is used.
8-byte alignment is guaranteed by normal malloc calls, so don't
bother calling memalign with an argument of 8 or less.
Overreliance on posix_memalign is a sure way to fragment space.
*/
int posix_memalign(void **memptr, size_t alignment, size_t size);
/*
valloc(size_t n);
Equivalent to memalign(pagesize, n), where pagesize is the page
@ -4507,6 +4523,18 @@ void* dlmemalign(size_t alignment, size_t bytes) {
return internal_memalign(gm, alignment, bytes);
}
int posix_memalign(void **memptr, size_t alignment, size_t size) {
int ret = 0;
*memptr = dlmemalign(alignment, size);
if (*memptr == 0) {
ret = ENOMEM;
}
return ret;
}
void** dlindependent_calloc(size_t n_elements, size_t elem_size,
void* chunks[]) {
size_t sz = elem_size; /* serves as 1-element array */

View file

@ -67,6 +67,8 @@ extern unsigned long strtoul(const char *, char **, int);
extern unsigned long long strtoull(const char *, char **, int);
extern double strtod(const char *nptr, char **endptr);
extern int posix_memalign(void **memptr, size_t alignment, size_t size);
static __inline__ float strtof(const char *nptr, char **endptr)
{
return (float)strtod(nptr, endptr);