File: c99_aligned_alloc.c

package info (click to toggle)
libjodycode 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,676 kB
  • sloc: ansic: 2,820; makefile: 372; sh: 160; xml: 37
file content (21 lines) | stat: -rw-r--r-- 475 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* Implementation of C11 aligned_alloc() using POSIX 2001 posix_memalign()
 *
 * Created by Jody Bruchon <jody@jodybruchon.com>
 *
 * Released into the public domain, and under the Creative Commons 0 license:
 * https://creativecommons.org/public-domain/cc0/
 */

#include <stdlib.h>
#include "c99_aligned_alloc.h"

void *aligned_alloc(size_t alignment, size_t size)
{
	void *mem;
	int i;

	i = posix_memalign(&mem, alignment, size);
	if (i != 0) mem = NULL;

	return mem;
}