Forward compatibility: libarossupport.a - remove dependency on C library
[AROS.git] / compiler / posixc / posix_memalign.c
blobc41d883dc3b4eabd677cbdf1b2062a2e582fe159
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX.1-2008 function posix_memalign().
6 */
8 #include <errno.h>
10 /*****************************************************************************
12 NAME */
13 #include <stdlib.h>
15 int posix_memalign (
17 /* SYNOPSIS */
18 void **memptr,
19 size_t alignment,
20 size_t size)
22 /* FUNCTION
23 Allocate aligned memory.
25 INPUTS
26 memptr - Pointer to a place to store the pointer to allocated memory.
27 alignment - Alignment of allocated memory. The address of the
28 allocated memory will be a multiple of this value, which
29 must be a power of two and a multiple of sizeof(void *).
30 size - How much memory to allocate.
32 RESULT
33 Returns zero on success.
34 Returns EINVAL if the alignment parameter was not a power of two, or
35 was not a multiple of sizeof(void *).
36 Returns ENOMEM if there was insufficient memory to fulfill the request.
38 NOTES
39 Memory allocated by posix_memalign() should be freed with free(). If
40 not, it will be freed when the program terminates.
42 If an error occurs, errno will not be set.
44 EXAMPLE
46 BUGS
48 SEE ALSO
49 stdc.library/malloc_align(), stdc.library/calloc(),
50 stdc.library/free(), stdc.library/malloc()
52 INTERNALS
54 ******************************************************************************/
56 int ret = 0, old_errno;
58 old_errno = errno;
60 *memptr = malloc_align(size, alignment);
61 if (!*memptr)
62 ret = errno;
64 errno = old_errno;
66 return ret;