]> pd.if.org Git - pdclib/blob - platform/posix/functions/_PDCLIB/_PDCLIB_allocpages.c
Add an up to date POSIX port (works on Mac OS X). This is fully functional except...
[pdclib] / platform / posix / functions / _PDCLIB / _PDCLIB_allocpages.c
1 /* _PDCLIB_allocpages( int const )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 /* This is an example implementation of _PDCLIB_allocpages() (declared in
8    _PDCLIB_config.h), fit for use with POSIX kernels.
9 */
10
11 #ifndef REGTEST
12 #include <stdint.h>
13 #include <stddef.h>
14 #include <sys/mman.h>
15 #include <_PDCLIB_glue.h>
16
17 void * _PDCLIB_allocpages( size_t n )
18 {
19     void *addr = mmap(
20         NULL, n * _PDCLIB_MALLOC_PAGESIZE, PROT_READ | PROT_WRITE,
21         MAP_ANON | MAP_PRIVATE, -1, 0);
22
23     if(addr != MAP_FAILED) {
24         return addr;
25     } else {
26         return NULL;
27     }
28 }
29
30 #endif
31
32 #ifdef TEST
33 #include <_PDCLIB_test.h>
34
35 int main( void )
36 {
37     return TEST_RESULTS;
38 }
39
40 #endif