X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fexample_cygwin%2Ffunctions%2F_PDCLIB%2Fallocpages.c;fp=platform%2Fexample_cygwin%2Ffunctions%2F_PDCLIB%2Fallocpages.c;h=0000000000000000000000000000000000000000;hb=0cd903b82201176f3148f6d18d68fd30b82746d5;hp=cf939712799f11f928759b67b5438e5fae03d9b8;hpb=56bacb39160e13397fde32a36329461f3ae56ec1;p=pdclib diff --git a/platform/example_cygwin/functions/_PDCLIB/allocpages.c b/platform/example_cygwin/functions/_PDCLIB/allocpages.c deleted file mode 100644 index cf93971..0000000 --- a/platform/example_cygwin/functions/_PDCLIB/allocpages.c +++ /dev/null @@ -1,72 +0,0 @@ -/* _PDCLIB_allocpages( int const ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is an example implementation of _PDCLIB_allocpages() (declared in - _PDCLIB_config.h), fit for use with POSIX kernels. -*/ - -#include -#include - -void * sbrk( intptr_t ); - -#include <_PDCLIB_glue.h> - -static void * membreak = NULL; - -void * _PDCLIB_allocpages( int const n ) -{ - if ( membreak == NULL ) - { - /* first call, make sure end-of-heap is page-aligned */ - intptr_t unaligned = 0; - membreak = sbrk( 0 ); - unaligned = _PDCLIB_PAGESIZE - (intptr_t)membreak % _PDCLIB_PAGESIZE; - if ( unaligned < _PDCLIB_PAGESIZE ) - { - /* end-of-heap not page-aligned - adjust */ - if ( sbrk( unaligned ) != membreak ) - { - /* error */ - return NULL; - } - membreak = (char *)membreak + unaligned; - } - } - /* increasing or decreasing heap - standard operation */ - void * oldbreak = membreak; - membreak = (void *)( (char *)membreak + ( n * _PDCLIB_PAGESIZE ) ); - if ( sbrk( (char*)membreak - (char*)oldbreak ) == membreak ) - { - /* successful */ - return oldbreak; - } - else - { - /* out of memory */ - membreak = oldbreak; - return NULL; - } -} - -#ifdef TEST -#include <_PDCLIB_test.h> - -int main( void ) -{ - char * startbreak = sbrk( 0 ); - TESTCASE( _PDCLIB_allocpages( 0 ) ); - TESTCASE( ( (char *)sbrk( 0 ) - startbreak ) <= _PDCLIB_PAGESIZE ); - startbreak = sbrk( 0 ); - TESTCASE( _PDCLIB_allocpages( 1 ) ); - TESTCASE( sbrk( 0 ) == startbreak + ( 1 * _PDCLIB_PAGESIZE ) ); - TESTCASE( _PDCLIB_allocpages( 5 ) ); - TESTCASE( sbrk( 0 ) == startbreak + ( 6 * _PDCLIB_PAGESIZE ) ); - TESTCASE( _PDCLIB_allocpages( -3 ) ); - TESTCASE( sbrk( 0 ) == startbreak + ( 3 * _PDCLIB_PAGESIZE ) ); -} - -#endif