-
Notifications
You must be signed in to change notification settings - Fork 19
/
memalign.c
42 lines (32 loc) · 833 Bytes
/
memalign.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#define EXTUNIX_WANT_MEMALIGN
#include "config.h"
#if defined(EXTUNIX_HAVE_MEMALIGN)
/*
* Binding to posix_memalign
*
* Copyright 2012 Goswin von Brederlow <[email protected]>
*
* License LGPL-2.1 with OCaml linking static exception
*
* For more information go to: www.talend.com
*
* author: Goswin von Brederlow <[email protected]>
*
*/
CAMLprim value caml_extunix_memalign(value valignment, value vsize)
{
CAMLparam2(valignment, vsize);
size_t alignment;
size_t size;
int errcode;
void *memptr;
alignment = Int_val(valignment);
size = Int_val(vsize);
errcode = posix_memalign(&memptr, alignment, size);
if (errcode != 0)
{
unix_error(errcode, "memalign", Nothing);
};
CAMLreturn(caml_ba_alloc_dims(CAML_BA_UINT8 | CAML_BA_C_LAYOUT | CAML_BA_MANAGED, 1, memptr, size));
}
#endif