summaryrefslogtreecommitdiff
path: root/r21/sources/android/support/src/posix_memalign.cpp
blob: cf7abbbf5b3dbfb77018c35038ff4a3a387ca296 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <errno.h>
#include <malloc.h>
#include <stdlib.h>

int posix_memalign(void** memptr, size_t alignment, size_t size) {
  if ((alignment & (alignment - 1)) != 0 || alignment == 0) {
    return EINVAL;
  }

  if (alignment % sizeof(void*) != 0) {
    return EINVAL;
  }

  *memptr = memalign(alignment, size);
  if (*memptr == NULL) {
    return errno;
  }

  return 0;
}