diff options
author | Jerry Jelinek <jerry.jelinek@joyent.com> | 2019-05-10 11:52:24 +0000 |
---|---|---|
committer | Jerry Jelinek <jerry.jelinek@joyent.com> | 2019-05-10 11:52:24 +0000 |
commit | f7bb5b64fd5e6f59f9038a2000f39d6cfa3851bc (patch) | |
tree | 1fc352d1448d483887c7fa3ef05fa454a88163e5 /usr/src/lib/libc | |
parent | 5273c8b74a4f5eab634e10181f7a5173e1303137 (diff) | |
parent | a547acf91a502e2d79ff67ef86d1b791883ca43a (diff) | |
download | illumos-joyent-f7bb5b64fd5e6f59f9038a2000f39d6cfa3851bc.tar.gz |
[illumos-gate merge]
commit a547acf91a502e2d79ff67ef86d1b791883ca43a
10880 posix_memalign() should avoid clobbering return parameter on failure
commit f26364c965228a50041eda19745fc8573312c654
10881 more C99 math macros should be compiler builtins
commit 9938df9efd1c845888adf3e046421db350cf1088
10882 math headers should stop supporting K&R C
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r-- | usr/src/lib/libc/port/gen/posix_memalign.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/usr/src/lib/libc/port/gen/posix_memalign.c b/usr/src/lib/libc/port/gen/posix_memalign.c index d05ac2d9ea..131e0d01b8 100644 --- a/usr/src/lib/libc/port/gen/posix_memalign.c +++ b/usr/src/lib/libc/port/gen/posix_memalign.c @@ -24,9 +24,10 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include "lint.h" + +#include <sys/sysmacros.h> + #include <stdlib.h> #include <errno.h> @@ -49,16 +50,19 @@ int posix_memalign(void **memptr, size_t alignment, size_t size) { void *ptr = NULL; - int error = 0; - - if (alignment == 0 || - (alignment & (sizeof (void *) - 1)) != 0 || - (alignment & (alignment - 1)) != 0) - error = EINVAL; - else if (size != 0 && - (ptr = memalign(alignment, size)) == NULL) - error = ENOMEM; - *memptr = ptr; - return (error); + if ((alignment == 0) || !ISP2(alignment) || + (alignment & (sizeof (void *) - 1)) != 0) { + return (EINVAL); + } else if (size == 0) { + *memptr = NULL; + return (0); + } else { + if ((ptr = memalign(alignment, size)) == NULL) { + return (ENOMEM); + } else { + *memptr = ptr; + return (0); + } + } } |