From 0c6fc51909e53bb89558858438a0267fcc44fea1 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 13 Mar 2008 18:11:33 +0000 Subject: r18793@catbus: nickm | 2008-03-13 14:09:19 -0400 Add a malloc_good_size() implementation to OpenBSD_malloc_Linux.c. Also, make configure.in not use support functions for the platform malloc when we are not using the platform mallocs. svn:r14010 --- src/common/OpenBSD_malloc_Linux.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') diff --git a/src/common/OpenBSD_malloc_Linux.c b/src/common/OpenBSD_malloc_Linux.c index 59c2c7def..da240c8e7 100644 --- a/src/common/OpenBSD_malloc_Linux.c +++ b/src/common/OpenBSD_malloc_Linux.c @@ -1998,3 +1998,21 @@ void *valloc(size_t size) posix_memalign(&r, malloc_pagesize, size); return r; } + +size_t malloc_good_size(size_t size) +{ + if (size == 0) { + return 1; + } else if (size <= malloc_maxsize) { + int i, j; + /* round up to the nearest power of 2, with same approach + * as malloc_bytes() uses. */ + j = 1; + i = size - 1; + while (i >>= 1) + j++; + return ((size_t)1) << j; + } else { + return pageround(size); + } +} -- cgit v1.2.3