diff options
author | jasone <jasone@FreeBSD.org> | 2006-01-12 09:29:38 +0000 |
---|---|---|
committer | jasone <jasone@FreeBSD.org> | 2006-01-12 09:29:38 +0000 |
commit | 958adbcf1809d37ffc55a46ff6ff83e321278156 (patch) | |
tree | dc1b6b34ccd9f732a2492983ab62fa818b5dd4bc /lib/libc/gen/valloc.c | |
parent | 6abe8a1c871e4dc46d382fe92b11c4608ea93fb8 (diff) | |
download | FreeBSD-src-958adbcf1809d37ffc55a46ff6ff83e321278156.zip FreeBSD-src-958adbcf1809d37ffc55a46ff6ff83e321278156.tar.gz |
Use posix_memalign() in valloc() rather than making assumptions about
the alignment of malloc()ed memory.
Approved by: markm (mentor)
Diffstat (limited to 'lib/libc/gen/valloc.c')
-rw-r--r-- | lib/libc/gen/valloc.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/libc/gen/valloc.c b/lib/libc/gen/valloc.c index 456f31d..9d888d3 100644 --- a/lib/libc/gen/valloc.c +++ b/lib/libc/gen/valloc.c @@ -41,12 +41,12 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> void * -valloc(i) - size_t i; +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; } |