diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-03-13 18:11:33 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-03-13 18:11:33 +0000 |
commit | 0c6fc51909e53bb89558858438a0267fcc44fea1 (patch) | |
tree | 40cf9625d20fd08ac5d752aeb11472afe1404994 /src | |
parent | 56580ae84e69bc4d1ce36012aa1003eb5303d6f9 (diff) | |
download | tor-0c6fc51909e53bb89558858438a0267fcc44fea1.tar tor-0c6fc51909e53bb89558858438a0267fcc44fea1.tar.gz |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/common/OpenBSD_malloc_Linux.c | 18 |
1 files changed, 18 insertions, 0 deletions
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); + } +} |