From: Sascha Wildner Date: Tue, 19 Aug 2014 20:08:47 +0000 (+0200) Subject: libc/valloc(): Use posix_memalign(). X-Git-Tag: v4.1.0~244 X-Git-Url: https://gitweb.dragonflybsd.org/~tuxillo/dragonfly.git/commitdiff_plain/e8c73df298554e0f4aa27f6ee8bca3533738ded0 libc/valloc(): Use posix_memalign(). Taken-from: FreeBSD --- diff --git a/lib/libc/gen/valloc.c b/lib/libc/gen/valloc.c index 3a780e13b5..b823f75ecf 100644 --- a/lib/libc/gen/valloc.c +++ b/lib/libc/gen/valloc.c @@ -10,10 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -31,7 +27,7 @@ * SUCH DAMAGE. * * @(#)valloc.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/gen/valloc.c,v 1.3 2005/11/13 00:07:42 swildner Exp $ + * $FreeBSD: head/lib/libc/gen/valloc.c 165903 2007-01-09 00:28:16Z imp $ */ #include @@ -40,9 +36,10 @@ void * valloc(size_t i) { - long valsiz = getpagesize(), j; - void *cp = malloc(i + (valsiz-1)); + void *ret; - j = ((long)cp + (valsiz-1)) &~ (valsiz-1); - return ((void *)j); + if (posix_memalign(&ret, getpagesize(), i) != 0) + ret = NULL; + + return ret; }