source: rtems/cpukit/libcsupport/src/posix_memalign.c @ 5580b93

Last change on this file since 5580b93 was 5580b93, checked in by Sebastian Huber <sebastian.huber@…>, on 05/05/21 at 06:46:24

libc: Reimplement posix_memlign()

Move all error checks into posix_memalign() so that the returned memory
pointer is set to NULL under all error conditions except
memptr == NULL.

Use parameter names of POSIX documentation.

  • Property mode set to 100644
File size: 906 bytes
Line 
1/**
2 * @file
3 *
4 * @ingroup libcsupport
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2008.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#ifdef RTEMS_NEWLIB
21#include "malloc_p.h"
22
23#include <stdlib.h>
24#include <errno.h>
25
26int posix_memalign(
27  void   **memptr,
28  size_t   alignment,
29  size_t   size
30)
31{
32  RTEMS_OBFUSCATE_VARIABLE( memptr );
33
34  if ( memptr == NULL ) {
35    return EINVAL;
36  }
37
38  *memptr = NULL;
39
40  if ( alignment < sizeof( void * ) ) {
41    return EINVAL;
42  }
43
44  if ( ( ( alignment - 1 ) & alignment ) != 0 ) {
45    return EINVAL;
46  }
47
48  *memptr = rtems_heap_allocate_aligned_with_boundary( size, alignment, 0 );
49
50  if ( *memptr == NULL ) {
51    return ENOMEM;
52  }
53
54  return 0;
55}
56#endif
Note: See TracBrowser for help on using the repository browser.