From 84e56ad2cf3f4b33089396bba6483888d54d99a3 Mon Sep 17 00:00:00 2001 From: tedu <> Date: Tue, 18 May 2010 22:24:55 +0000 Subject: add posix_madvise, posix_memalign, strndup, and strnlen. mostly from brad and millert, with hints from guenther, jmc, and otto I think. ok previous. --- src/lib/libc/stdlib/malloc.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/lib/libc/stdlib/malloc.c') diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 9cee3e5935..902b69c216 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/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 * @@ -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; +} + -- cgit v1.2.3-55-g6feb