]> pd.if.org Git - pdclib/blobdiff - platform/example/functions/_PDCLIB/allocpages.c
PDCLib includes with quotes, not <>.
[pdclib] / platform / example / functions / _PDCLIB / allocpages.c
index 48b8dc9cad8ea4ddaa8015501b02a6276db4b42e..27c56103a9df9f8c027de51b7276e4a4177f47bb 100644 (file)
@@ -1,85 +1,28 @@
-/* $Id$ */
-
-/* Release $Name$ */
-
 /* _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.
+/* This is a stub implementation of _PDCLIB_allocpages
 */
 
 #include <stdint.h>
+#include <stddef.h>
+#include "_PDCLIB_glue.h"
+#include <errno.h>
 
-#include <unistd.h>
-
-#ifndef _PDCLIB_CONFIG_H
-#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H
-#include <_PDCLIB_config.h>
-#endif
-
-static void * membreak = NULL;
-
-void * _PDCLIB_allocpages( int const n )
+void * _PDCLIB_allocpages( size_t 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 += unaligned;
-        }
-    }
-    /* increasing or decreasing heap - standard operation */
-    void * oldbreak = membreak;
-    membreak = (void *)( (char *)membreak + ( n * _PDCLIB_PAGESIZE ) );
-    if ( brk( membreak ) == 0 )
-    {
-        /* successful */
-        return oldbreak;
-    }
-    else
-    {
-        /* out of memory */
-        membreak = oldbreak;
-        return NULL;
-    }
+    errno = ENOTSUP;
+    return NULL;
 }
 
 #ifdef TEST
-#include <_PDCLIB_test.h>
+#include "_PDCLIB_test.h"
 
-int puts( const char * );
-
-int main()
+int main( void )
 {
-    BEGIN_TESTS;
-#ifndef REGTEST
-    {
-    void * startbreak = sbrk( 0 );
-    TESTCASE( _PDCLIB_allocpages( 0 ) );
-    TESTCASE( ( 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
     return TEST_RESULTS;
 }