diff options
Diffstat (limited to 'lib/libc/stdlib/malloc.c')
-rw-r--r-- | lib/libc/stdlib/malloc.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 9cee3e5935f..902b69c2162 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.124 2010/01/13 12:40:11 otto Exp $ */ +/* $OpenBSD: malloc.c,v 1.125 2010/05/18 22:24:55 tedu Exp $ */ /* * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> * @@ -1488,3 +1488,28 @@ calloc(size_t nmemb, size_t size) return r; } +int +posix_memalign(void **memptr, size_t alignment, size_t size) +{ + void *result; + + /* Make sure that alignment is a large enough power of 2. */ + if (((alignment - 1) & alignment) != 0 || alignment < sizeof(void *) || + alignment > MALLOC_PAGESIZE) + return EINVAL; + + /* + * max(size, alignment) is enough to assure the requested alignment, + * since the allocator always allocates power-of-two blocks. + */ + if (size < alignment) + size = alignment; + result = malloc(size); + + if (result == NULL) + return ENOMEM; + + *memptr = result; + return 0; +} + |