]> pd.if.org Git - pdclib.old/commitdiff
* platform/example is now a "stub" platform - it should compile anywhere, but
authorOwen Shepherd <owen.shepherd@e43.eu>
Sun, 5 Aug 2012 23:01:01 +0000 (00:01 +0100)
committerOwen Shepherd <owen.shepherd@e43.eu>
Sun, 5 Aug 2012 23:01:01 +0000 (00:01 +0100)
  be useful nowhere.
* The old platform/example code has been moved to platform/posix - it should
  become a base implementation which works on any POSIX system
* A platform/win32 is probably due. This will be special in that it won't depend
  upon the host OS' libc (instead depending directly upon kernel32)

45 files changed:
platform/example/functions/_PDCLIB/_Exit.c
platform/example/functions/_PDCLIB/allocpages.c
platform/example/functions/_PDCLIB/close.c
platform/example/functions/_PDCLIB/fillbuffer.c
platform/example/functions/_PDCLIB/flushbuffer.c
platform/example/functions/_PDCLIB/open.c
platform/example/functions/_PDCLIB/rename.c
platform/example/functions/_PDCLIB/seek.c
platform/example/functions/stdio/remove.c
platform/example/functions/stdio/tmpfile.c
platform/example/functions/stdlib/getenv.c
platform/example/functions/stdlib/system.c
platform/example/includes/float.h
platform/example/includes/signal.h
platform/example/internals/_PDCLIB_config.h
platform/example_64/internals/_PDCLIB_config.h [deleted file]
platform/example_cygwin/Makefile [deleted file]
platform/example_cygwin/functions/_PDCLIB/stdinit.c [deleted file]
platform/example_cygwin/functions/stdio/tmpfile.c [deleted file]
platform/posix/Readme.txt [moved from platform/example_cygwin/Readme.txt with 100% similarity]
platform/posix/functions/_PDCLIB/_Exit.c [moved from platform/example_cygwin/functions/_PDCLIB/_Exit.c with 100% similarity]
platform/posix/functions/_PDCLIB/allocpages.c [moved from platform/example_cygwin/functions/_PDCLIB/allocpages.c with 94% similarity]
platform/posix/functions/_PDCLIB/allocpages.o [new file with mode: 0644]
platform/posix/functions/_PDCLIB/close.c [moved from platform/example_cygwin/functions/_PDCLIB/close.c with 100% similarity]
platform/posix/functions/_PDCLIB/close.o [new file with mode: 0644]
platform/posix/functions/_PDCLIB/fillbuffer.c [moved from platform/example_cygwin/functions/_PDCLIB/fillbuffer.c with 98% similarity]
platform/posix/functions/_PDCLIB/flushbuffer.c [moved from platform/example_cygwin/functions/_PDCLIB/flushbuffer.c with 100% similarity]
platform/posix/functions/_PDCLIB/open.c [moved from platform/example_cygwin/functions/_PDCLIB/open.c with 97% similarity]
platform/posix/functions/_PDCLIB/rename.c [moved from platform/example_cygwin/functions/_PDCLIB/rename.c with 95% similarity]
platform/posix/functions/_PDCLIB/seek.c [moved from platform/example_cygwin/functions/_PDCLIB/seek.c with 76% similarity]
platform/posix/functions/_PDCLIB/stdinit.c [new file with mode: 0644]
platform/posix/functions/_PDCLIB/stdinit.o [new file with mode: 0644]
platform/posix/functions/signal/raise.c [moved from platform/example_cygwin/functions/signal/raise.c with 100% similarity]
platform/posix/functions/signal/raise.o [new file with mode: 0644]
platform/posix/functions/signal/signal.c [moved from platform/example_cygwin/functions/signal/signal.c with 93% similarity]
platform/posix/functions/signal/signal.o [new file with mode: 0644]
platform/posix/functions/stdio/remove.c [moved from platform/example_cygwin/functions/stdio/remove.c with 79% similarity]
platform/posix/functions/stdio/tmpfile.c [new file with mode: 0644]
platform/posix/functions/stdlib/getenv.c [moved from platform/example_cygwin/functions/stdlib/getenv.c with 100% similarity]
platform/posix/functions/stdlib/getenv.o [new file with mode: 0644]
platform/posix/functions/stdlib/system.c [moved from platform/example_cygwin/functions/stdlib/system.c with 72% similarity]
platform/posix/functions/stdlib/system.o [new file with mode: 0644]
platform/posix/includes/float.h [moved from platform/example_cygwin/includes/float.h with 97% similarity]
platform/posix/includes/signal.h [moved from platform/example_cygwin/includes/signal.h with 97% similarity]
platform/posix/internals/_PDCLIB_config.h [moved from platform/example_cygwin/internals/_PDCLIB_config.h with 68% similarity]

index 5c95fca8c03379452931b1fda5beaa6b9e38afb3..2bfc8c90623057182779167bb03df4b3ec92abb3 100644 (file)
@@ -6,20 +6,18 @@
    Permission is granted to use, modify, and / or redistribute at will.
 */
 
-/* This is an example implementation of _PDCLIB_exit() fit for use with POSIX
-   kernels.
+/* This is a stub implementation of _PDCLIB_Exit
 */
 
 #include <stdlib.h>
 
 #ifndef REGTEST
 #include <_PDCLIB_glue.h>
-
-extern void _exit( int status ) _PDCLIB_NORETURN;
+#include <errno.h>
 
 void _PDCLIB_Exit( int status )
 {
-    _exit( status );
+    errno = ENOTSUP;
 }
 
 #endif
index 435e8c64b8840fa7c429f2faadaf9d81caca3d8a..aa997f67338237a15ef37f2ebe3f6020e65ec24c 100644 (file)
@@ -6,56 +6,20 @@
    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>
-
-int brk( void * );
-void * sbrk( intptr_t );
-
-#ifndef _PDCLIB_GLUE_H
-#define _PDCLIB_GLUE_H _PDCLIB_GLUE_H
 #include <_PDCLIB_glue.h>
-#endif
+#include <errno.h>
 
 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 = (char *)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
@@ -63,20 +27,6 @@ void * _PDCLIB_allocpages( int const n )
 
 int main( void )
 {
-#ifndef REGTEST
-    {
-    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
     return TEST_RESULTS;
 }
 
index c4b61738794444b55c1a5e387c6c7bf5315c68b0..1b030c963e8bb058f1643b1934ce4aea67c70fe1 100644 (file)
@@ -6,20 +6,19 @@
    Permission is granted to use, modify, and / or redistribute at will.
 */
 
-/* This is an example implementation of _PDCLIB_close() fit for use with POSIX
-   kernels.
+/* This is a stub example implementation of _PDCLIB_close()
 */
 
 #include <stdio.h>
 
 #ifndef REGTEST
 #include <_PDCLIB_glue.h>
-
-extern int close( int fd );
+#include <errno.h>
 
 int _PDCLIB_close( int fd )
 {
-    return close( fd );
+    errno = ENOTSUP;
+    return 1;
 }
 
 #endif
index 1d450259e55ee8721b3a92b0172ec8a77cd20869..c961f48dfdeb92c607e3ed3f29549de8be9526eb 100644 (file)
@@ -6,60 +6,18 @@
    Permission is granted to use, modify, and / or redistribute at will.
 */
 
-/* This is an example implementation of _PDCLIB_fillbuffer() fit for
-   use with POSIX kernels.
+/* This is a stub version of _PDCLIB_fillbuffer
 */
 
 #include <stdio.h>
 
 #ifndef REGTEST
 #include <_PDCLIB_glue.h>
-
-#include </usr/include/errno.h>
-
-typedef long ssize_t;
-extern ssize_t read( int fd, void * buf, size_t count );
+#include <errno.h>
 
 int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream )
 {
-    /* No need to handle buffers > INT_MAX, as PDCLib doesn't allow them */
-    ssize_t rc = read( stream->handle, stream->buffer, stream->bufsize );
-    if ( rc > 0 )
-    {
-        /* Reading successful. */
-        if ( ! ( stream->status & _PDCLIB_FBIN ) )
-        {
-            /* TODO: Text stream conversion here */
-        }
-        stream->pos.offset += rc;
-        stream->bufend = rc;
-        stream->bufidx = 0;
-        return 0;
-    }
-    if ( rc < 0 )
-    {
-        /* Reading error */
-        switch ( errno )
-        {
-            /* See comments on implementation-defined errno values in
-               <_PDCLIB_config.h>.
-            */
-            case EBADF:
-            case EFAULT:
-            case EINTR:
-            case EINVAL:
-            case EIO:
-                _PDCLIB_errno = _PDCLIB_ERROR;
-                break;
-            default:
-                /* This should be something like EUNKNOWN. */
-                _PDCLIB_errno = _PDCLIB_ERROR;
-                break;
-        }
-        stream->status |= _PDCLIB_ERRORFLAG;
-        return EOF;
-    }
-    /* End-of-File */
+    errno = ENOTSUP; 
     stream->status |= _PDCLIB_EOFFLAG;
     return EOF;
 }
index e68c6c49041875243d7e983211b682e0e4bbd28c..6dc11640017e78bf9cc1aa46eff206cc60f8d97f 100644 (file)
@@ -6,8 +6,7 @@
    Permission is granted to use, modify, and / or redistribute at will.
 */
 
-/* This is an example implementation of _PDCLIB_flushbuffer() fit for
-   use with POSIX kernels.
+/* This is a stub implementation of _PDCLIB_flushbuffer
 */
 
 #include <stdio.h>
 
 #ifndef REGTEST
 #include <_PDCLIB_glue.h>
-
-#include </usr/include/errno.h>
-
-typedef long ssize_t;
-extern ssize_t write( int fd, const void * buf, size_t count );
-
-/* The number of attempts to complete an output buffer flushing before giving
- *    up.
- *    */
-#define _PDCLIB_IO_RETRIES 1
-
-/* What the system should do after an I/O operation did not succeed, before   */
-/* trying again. (Empty by default.)                                          */
-#define _PDCLIB_IO_RETRY_OP( stream )
+#include <errno.h>
 
 int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream )
 {
-    if ( ! ( stream->status & _PDCLIB_FBIN ) )
-    {
-        /* TODO: Text stream conversion here */
-    }
-    /* No need to handle buffers > INT_MAX, as PDCLib doesn't allow them */
-    _PDCLIB_size_t written = 0;
-    int rc;
-    /* Keep trying to write data until everything is written, an error
-       occurs, or the configured number of retries is exceeded.
-    */
-    for ( unsigned int retries = _PDCLIB_IO_RETRIES; retries > 0; --retries )
-    {
-        rc = (int)write( stream->handle, stream->buffer + written, stream->bufidx - written );
-        if ( rc < 0 )
-        {
-            /* Write error */
-            switch ( errno )
-            {
-                /* See <_PDCLIB_config.h>. There should be differenciated errno
-                   handling here, possibly even a 1:1 mapping; but that is up
-                   to the individual platform.
-                */
-                case EBADF:
-                case EFAULT:
-                case EFBIG:
-                case EINTR:
-                case EINVAL:
-                case EIO:
-                case ENOSPC:
-                case EPIPE:
-                    _PDCLIB_errno = _PDCLIB_ERROR;
-                    break;
-                default:
-                    /* This should be something like EUNKNOWN. */
-                    _PDCLIB_errno = _PDCLIB_ERROR;
-                    break;
-            }
-            stream->status |= _PDCLIB_ERRORFLAG;
-            /* Move unwritten remains to begin of buffer. */
-            stream->bufidx -= written;
-            memmove( stream->buffer, stream->buffer + written, stream->bufidx );
-            return EOF;
-        }
-        written += (_PDCLIB_size_t)rc;
-        stream->pos.offset += rc;
-        if ( written == stream->bufidx )
-        {
-            /* Buffer written completely. */
-            stream->bufidx = 0;
-            return 0;
-        }
-    }
-    /* Number of retries exceeded. You probably want a different errno value
-       here.
-    */
-    _PDCLIB_errno = _PDCLIB_ERROR;
-    stream->status |= _PDCLIB_ERRORFLAG;
-    /* Move unwritten remains to begin of buffer. */
-    stream->bufidx -= written;
-    memmove( stream->buffer, stream->buffer + written, stream->bufidx );
+    errno = ENOTSUP;
     return EOF;
 }
 
index 2098dd360a866b65db4a7f9a5c5a249d4f72020c..1d292f6e3c15892fa8e46eee4fc599994569ae8e 100644 (file)
@@ -6,92 +6,19 @@
    Permission is granted to use, modify, and / or redistribute at will.
 */
 
-/* This is an example implementation of _PDCLIB_open() fit for use with POSIX
-   kernels.
+/* This is a stub implementation of open.
 */
 
 #include <stdio.h>
+#include <errno.h>
 
 #ifndef REGTEST
 #include <_PDCLIB_glue.h>
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "/usr/include/errno.h"
-
 int _PDCLIB_open( char const * const filename, unsigned int mode )
 {
-    /* This is an example implementation of _PDCLIB_open() fit for use with
-       POSIX kernels.
-    */
-    int osmode;
-    switch ( mode & ( _PDCLIB_FREAD | _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_FRW ) )
-    {
-        case _PDCLIB_FREAD: /* "r" */
-            osmode = O_RDONLY;
-            break;
-        case _PDCLIB_FWRITE: /* "w" */
-            osmode = O_WRONLY | O_CREAT | O_TRUNC;
-            break;
-        case _PDCLIB_FAPPEND: /* "a" */
-            osmode = O_WRONLY | O_APPEND | O_CREAT;
-            break;
-        case _PDCLIB_FREAD | _PDCLIB_FRW: /* "r+" */
-            osmode = O_RDWR;
-            break;
-        case _PDCLIB_FWRITE | _PDCLIB_FRW: /* "w+" */
-            osmode = O_RDWR | O_CREAT | O_TRUNC;
-            break;
-        case _PDCLIB_FAPPEND | _PDCLIB_FRW: /* "a+" */
-            osmode = O_RDWR | O_APPEND | O_CREAT;
-            break;
-        default: /* Invalid mode */
-            return -1;
-    }
-    int rc;
-    if ( osmode & O_CREAT )
-    {
-        rc = open( filename, osmode, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH );
-    }
-    else
-    {
-        rc = open( filename, osmode );
-    }
-    if ( rc == -1 )
-    {
-        switch ( errno )
-        {
-            /* See the comments on implementation-defined errno values in
-               <_PDCLIB_config.h>.
-            */
-            case EACCES:
-            case EFAULT:
-            case EINTR:
-            case EISDIR:
-            case ELOOP:
-            case EMFILE:
-            case ENAMETOOLONG:
-            case ENFILE:
-            case ENODEV:
-            case ENOENT:
-            case ENOMEM:
-            case ENOSPC:
-            case ENOTDIR:
-            case EOVERFLOW:
-            case EROFS:
-            case ETXTBSY:
-                _PDCLIB_errno = _PDCLIB_ERROR;
-                break;
-            default:
-                /* This should be something like EUNKNOWN. */
-                _PDCLIB_errno = _PDCLIB_ERROR;
-                break;
-        }
-    }
-    return rc;
+    errno = ENOTSUP;
+    return 1;
 }
 
 #endif
@@ -104,61 +31,6 @@ int _PDCLIB_open( char const * const filename, unsigned int mode )
 
 int main( void )
 {
-    /* This testdriver assumes POSIX, i.e. _PDCLIB_fd_t being int and being
-       incremented by one on each successful open.
-    */
-    int fh;
-    char buffer[ 10 ];
-    remove( testfile );
-    /* Trying to read non-existent file. */
-    TESTCASE( _PDCLIB_open( testfile, _PDCLIB_FREAD ) == _PDCLIB_NOHANDLE );
-    /* Writing to file, trying to read from it. */
-    TESTCASE( ( fh = _PDCLIB_open( testfile, _PDCLIB_FWRITE ) ) != _PDCLIB_NOHANDLE );
-    TESTCASE( write( fh, "test", 4 ) == 4 );
-    TESTCASE( lseek( fh, 0, SEEK_SET ) == 0 );
-    TESTCASE( read( fh, buffer, 4 ) == -1 );
-    TESTCASE( _PDCLIB_close( fh ) == 0 );
-    /* Reading from file, trying to write to it. */
-    TESTCASE( ( fh = _PDCLIB_open( testfile, _PDCLIB_FREAD ) ) != _PDCLIB_NOHANDLE );
-    TESTCASE( write( fh, "test", 4 ) == -1 );
-    TESTCASE( _PDCLIB_close( fh ) == 0 );
-    /* Appending to file, trying to read from it. */
-    TESTCASE( ( fh = _PDCLIB_open( testfile, _PDCLIB_FAPPEND ) ) != _PDCLIB_NOHANDLE );
-    TESTCASE( write( fh, "app", 3 ) == 3 );
-    TESTCASE( lseek( fh, 0, SEEK_SET ) == 0 );
-    TESTCASE( read( fh, buffer, 10 ) == -1 );
-    TESTCASE( write( fh, "end", 3 ) == 3 );
-    TESTCASE( _PDCLIB_close( fh ) == 0 );
-    /* Reading and writing from file ("r+"). */
-    TESTCASE( ( fh = _PDCLIB_open( testfile, _PDCLIB_FREAD | _PDCLIB_FRW ) ) != _PDCLIB_NOHANDLE );
-    TESTCASE( read( fh, buffer, 10 ) == 10 );
-    TESTCASE( memcmp( buffer, "testappend", 10 ) == 0 );
-    TESTCASE( lseek( fh, 0, SEEK_SET ) == 0 );
-    TESTCASE( write( fh, "wedo", 4 ) == 4 );
-    TESTCASE( lseek( fh, 0, SEEK_SET ) == 0 );
-    TESTCASE( read( fh, buffer, 10 ) == 10 );
-    TESTCASE( memcmp( buffer, "wedoappend", 10 ) == 0 );
-    TESTCASE( _PDCLIB_close( fh ) == 0 );
-    /* Writing and reading from file ("w+"). */
-    TESTCASE( ( fh = _PDCLIB_open( testfile, _PDCLIB_FWRITE | _PDCLIB_FRW ) ) != _PDCLIB_NOHANDLE );
-    TESTCASE( write( fh, "test", 4 ) == 4 );
-    TESTCASE( lseek( fh, 1, SEEK_SET ) == 1 );
-    TESTCASE( read( fh, buffer, 2 ) == 2 );
-    TESTCASE( memcmp( buffer, "es", 2 ) == 0 );
-    TESTCASE( write( fh, "sie", 3 ) == 3 );
-    TESTCASE( lseek( fh, 0, SEEK_SET ) == 0 );
-    TESTCASE( read( fh, buffer, 6 ) == 6 );
-    TESTCASE( memcmp( buffer, "tessie", 6 ) == 0 );
-    TESTCASE( _PDCLIB_close( fh ) == 0 );
-    /* Appending and reading from file ("a+"). */
-    TESTCASE( ( fh = _PDCLIB_open( testfile, _PDCLIB_FAPPEND | _PDCLIB_FRW ) ) != _PDCLIB_NOHANDLE );
-    TESTCASE( write( fh, "baby", 4 ) == 4 );
-    TESTCASE( lseek( fh, 0, SEEK_SET ) == 0 );
-    TESTCASE( read( fh, buffer, 10 ) == 10 );
-    TESTCASE( memcmp( buffer, "tessiebaby", 10 ) == 0 );
-    TESTCASE( _PDCLIB_close( fh ) == 0 );
-    /* Cleaning up. */
-    TESTCASE( remove( testfile ) == 0 );
     return TEST_RESULTS;
 }
 
index a37eeb3464ed74a22d30a4ee4fbd7280479b1a8c..a65715dfc4f9dd591b43e0dd5e380024cdf92bfb 100644 (file)
 
 #ifndef REGTEST
 #include <_PDCLIB_glue.h>
-
-#include </usr/include/errno.h>
-
-extern int unlink( const char * pathname );
-extern int link( const char * old, const char * new );
+#include <errno.h>
 
 int _PDCLIB_rename( const char * old, const char * new )
 {
-    /* Note that the behaviour if new file exists is implementation-defined.
-       There is nothing wrong with either overwriting it or failing the
-       operation, but you might want to document whichever you chose.
-       This example fails if new file exists.
-    */
-    if ( link( old, new ) == 0 )
-    {
-        if ( unlink( old ) == EOF )
-        {
-            switch ( errno )
-            {
-                /* See the comments on implementation-defined errno values in
-                   <_PDCLIB_config.h>.
-                */
-                case EACCES:
-                case EFAULT:
-                case EIO:
-                case EISDIR:
-                case ELOOP:
-                case ENAMETOOLONG:
-                case ENOENT:
-                case ENOMEM:
-                case ENOTDIR:
-                case EPERM:
-                case EROFS:
-                    _PDCLIB_errno = _PDCLIB_ERROR;
-                    break;
-                default:
-                    /* This should be something like EUNKNOWN. */
-                    _PDCLIB_errno = _PDCLIB_ERROR;
-                    break;
-            }
-            return -1;
-        }
-        else
-        {
-            return 0;
-        }
-    }
-    else
-    {
-        switch ( errno )
-        {
-            /* See the comments on implementation-defined errno values in
-               <_PDCLIB_config.h>.
-            */
-            case EACCES:
-            case EEXIST:
-            case EFAULT:
-            case EIO:
-            case ELOOP:
-            case EMLINK:
-            case ENAMETOOLONG:
-            case ENOENT:
-            case ENOMEM:
-            case ENOSPC:
-            case ENOTDIR:
-            case EPERM:
-            case EROFS:
-            case EXDEV:
-                _PDCLIB_errno = _PDCLIB_ERROR;
-                break;
-            default:
-                /* This should be something like EUNKNOWN. */
-                _PDCLIB_errno = _PDCLIB_ERROR;
-                break;
-        }
-        return EOF;
-    }
+    errno = ENOTSUP;
 }
 
 #endif
@@ -98,41 +26,6 @@ int _PDCLIB_rename( const char * old, const char * new )
 
 int main( void )
 {
-    FILE * file;
-    remove( testfile1 );
-    remove( testfile2 );
-    /* check that neither file exists */
-    TESTCASE( fopen( testfile1, "r" ) == NULL );
-    TESTCASE( fopen( testfile2, "r" ) == NULL );
-    /* rename file 1 to file 2 - expected to fail */
-    TESTCASE( _PDCLIB_rename( testfile1, testfile2 ) == -1 );
-    /* create file 1 */
-    TESTCASE( ( file = fopen( testfile1, "w" ) ) != NULL );
-    TESTCASE( fputc( 'x', file ) == 'x' );
-    TESTCASE( fclose( file ) == 0 );
-    /* check that file 1 exists */
-    TESTCASE( ( file = fopen( testfile1, "r" ) ) != NULL );
-    TESTCASE( fclose( file ) == 0 );
-    /* rename file 1 to file 2 */
-    TESTCASE( _PDCLIB_rename( testfile1, testfile2 ) == 0 );
-    /* check that file 2 exists, file 1 does not */
-    TESTCASE( fopen( testfile1, "r" ) == NULL );
-    TESTCASE( ( file = fopen( testfile2, "r" ) ) != NULL );
-    TESTCASE( fclose( file ) == 0 );
-    /* create another file 1 */
-    TESTCASE( ( file = fopen( testfile1, "w" ) ) != NULL );
-    TESTCASE( fputc( 'x', file ) == 'x' );
-    TESTCASE( fclose( file ) == 0 );
-    /* check that file 1 exists */
-    TESTCASE( ( file = fopen( testfile1, "r" ) ) != NULL );
-    TESTCASE( fclose( file ) == 0 );
-    /* rename file 1 to file 2 - expected to fail, see comment in
-       _PDCLIB_rename() itself.
-    */
-    TESTCASE( _PDCLIB_rename( testfile1, testfile2 ) == -1 );
-    /* remove both files */
-    remove( testfile1 );
-    remove( testfile2 );
     return TEST_RESULTS;
 }
 
index 755abe2cb1eb9393a943356007f9071a69b9f2de..381baef05b9ba5de8f6d0d90e8ba107f869646ef 100644 (file)
@@ -7,56 +7,12 @@
 */
 
 #include <stdio.h>
-
-#ifndef _PDCLIB_GLUE_H
-#define _PDCLIB_GLUE_H
+#include <errno.h>
 #include <_PDCLIB_glue.h>
-#endif
-
-#include "/usr/include/errno.h"
-
-extern _PDCLIB_int64_t lseek64( int fd, _PDCLIB_int64_t offset, int whence );
 
 _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence )
 {
-    switch ( whence )
-    {
-        case SEEK_SET:
-        case SEEK_CUR:
-        case SEEK_END:
-            /* EMPTY - OK */
-            break;
-        default:
-            /* See comments on implementation-defined errno values in
-               <_PDCLIB_config.h>.
-            */
-            _PDCLIB_errno = _PDCLIB_ERROR;
-            return EOF;
-            break;
-    }
-    _PDCLIB_int64_t rc = lseek64( stream->handle, offset, whence );
-    if ( rc != EOF )
-    {
-        stream->ungetidx = 0;
-        stream->bufidx = 0;
-        stream->bufend = 0;
-        stream->pos.offset = rc;
-        return rc;
-    }
-    switch ( errno )
-    {
-        case EBADF:
-        case EFAULT:
-            /* See comments on implementation-defined errno values in
-               <_PDCLIB_config.h>.
-            */
-            _PDCLIB_errno = _PDCLIB_ERROR;
-            break;
-        default:
-            /* This should be something like EUNKNOWN. */
-            _PDCLIB_errno = _PDCLIB_ERROR;
-            break;
-    }
+    errno = ENOTSUP;
     return EOF;
 }
 
index 389df301be224d6945d6b8a250f7e31a82ca7543..0c4f050f29b477598d87612f52af18a3a6d08ccd 100644 (file)
 #ifndef REGTEST
 
 #include <string.h>
-
-#include "/usr/include/errno.h"
+#include <errno.h>
 
 extern struct _PDCLIB_file_t * _PDCLIB_filelist;
 
-extern int unlink( const char * pathname );
-
 int remove( const char * pathname )
 {
-    int rc;
-    struct _PDCLIB_file_t * current = _PDCLIB_filelist;
-    while ( current != NULL )
-    {
-        if ( ( current->filename != NULL ) && ( strcmp( current->filename, pathname ) == 0 ) )
-        {
-            return EOF;
-        }
-        current = current->next;
-    }
-    if ( ( rc = unlink( pathname ) ) == -1 )
-    {
-        switch ( errno )
-        {
-            /* See the comments on implementation-defined errno values in
-               <_PDCLIB_config.h>.
-            */
-            case EACCES:
-            case EFAULT:
-            case EIO:
-            case EISDIR:
-            case ELOOP:
-            case ENAMETOOLONG:
-            case ENOENT:
-            case ENOMEM:
-            case ENOTDIR:
-            case EPERM:
-            case EROFS:
-                _PDCLIB_errno = _PDCLIB_ERROR;
-                break;
-            default:
-                /* This should be something like EUNKNOWN. */
-                _PDCLIB_errno = _PDCLIB_ERROR;
-                break;
-        }
-    }
-    return rc;
+    errno = ENOTSUP;
+    return 1;
 }
 
 #endif
index 29750d46b2a7757cf785c10fa9756dfc98503622..2d52f60b38c06e7e57712ea3f7e6949d3fa3650f 100644 (file)
 
 #ifndef REGTEST
 
-#include <inttypes.h>
-#include <stdlib.h>
-#include <string.h>
-
+#include <errno.h>
 #include <_PDCLIB_glue.h>
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
 extern struct _PDCLIB_file_t * _PDCLIB_filelist;
 
-/* This is an example implementation of tmpfile() fit for use with POSIX
-   kernels.
+/* This is a stub implementation of tmpfile
 */
 struct _PDCLIB_file_t * tmpfile( void )
 {
-    FILE * rc;
-    /* This is the chosen way to get high-quality randomness. Replace as
-       appropriate.
-    */
-    FILE * randomsource = fopen( "/proc/sys/kernel/random/uuid", "rb" );
-    char filename[ L_tmpnam ];
-    _PDCLIB_fd_t fd;
-    if ( randomsource == NULL )
-    {
-        return NULL;
-    }
-    for ( ;; )
-    {
-        /* Get a filename candidate. What constitutes a valid filename and
-           where temporary files are usually located is platform-dependent,
-           which is one reason why this function is located in the platform
-           overlay. The other reason is that a *good* implementation should
-           use high-quality randomness instead of a pseudo-random sequence to
-           generate the filename candidate, which is *also* platform-dependent.
-        */
-        unsigned int random;
-        fscanf( randomsource, "%u", &random ); 
-        sprintf( filename, "/tmp/%u.tmp", random );
-        /* Check if file of this name exists. Note that fopen() is a very weak
-           check, which does not take e.g. access permissions into account
-           (file might exist but not readable). Replace with something more
-           appropriate.
-        */
-        fd = open( filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR );
-        if ( fd != -1 )
-        {
-            break;
-        }
-        close( fd );
-    }
-    fclose( randomsource );
-    /* See fopen(). */
-    if ( ( rc = calloc( 1, sizeof( struct _PDCLIB_file_t ) + _PDCLIB_UNGETCBUFSIZE + L_tmpnam + BUFSIZ ) ) == NULL )
-    {
-        /* No memory to set up FILE structure */
-        close( fd );
-        return NULL;
-    }
-    rc->status = _PDCLIB_filemode( "wb+" ) | _IOLBF | _PDCLIB_DELONCLOSE;
-    rc->handle = fd;
-    rc->ungetbuf = (unsigned char *)rc + sizeof( struct _PDCLIB_file_t );
-    rc->filename = (char *)rc->ungetbuf + _PDCLIB_UNGETCBUFSIZE;
-    rc->buffer   = rc->filename + L_tmpnam;
-    strcpy( rc->filename, filename );
-    rc->bufsize = BUFSIZ;
-    rc->bufidx = 0;
-    rc->ungetidx = 0;
-    rc->next = _PDCLIB_filelist;
-    _PDCLIB_filelist = rc;
-    return rc;
+    errno = ENOTSUP;
+    return 1;
 }
 
 #endif
@@ -93,21 +31,6 @@ struct _PDCLIB_file_t * tmpfile( void )
 
 int main( void )
 {
-    FILE * fh;
-#ifndef REGTEST
-    char filename[ L_tmpnam ];
-    FILE * fhtest;
-#endif
-    TESTCASE( ( fh = tmpfile() ) != NULL );
-    TESTCASE( fputc( 'x', fh ) == 'x' );
-    /* Checking that file is actually there */
-    TESTCASE_NOREG( strcpy( filename, fh->filename ) == filename );
-    TESTCASE_NOREG( ( fhtest = fopen( filename, "r" ) ) != NULL );
-    TESTCASE_NOREG( fclose( fhtest ) == 0 );
-    /* Closing tmpfile */
-    TESTCASE( fclose( fh ) == 0 );
-    /* Checking that file was deleted */
-    TESTCASE_NOREG( fopen( filename, "r" ) == NULL );
     return TEST_RESULTS;
 }
 
index 4eb70102e54614867676813e30ba6a4d8ec18184..a95171d9ab2cb4300a8103e5b9b62e93b9459695 100644 (file)
@@ -6,7 +6,7 @@
    Permission is granted to use, modify, and / or redistribute at will.
 */
 
-/* This is an example implementation of getenv() fit for use with POSIX kernels.
+/* This is a stub implementation of getenv
 */
 
 #include <string.h>
 
 #ifndef REGTEST
 
-extern char * * environ;
-
 char * getenv( const char * name )
 {
-    size_t len = strlen( name );
-    size_t index = 0;
-    while ( environ[ index ] != NULL )
-    {
-        if ( strncmp( environ[ index ], name, len ) == 0 )
-        {
-            return environ[ index ] + len + 1;
-        }
-        index++;
-    }
     return NULL;
 }
 
@@ -38,8 +26,6 @@ char * getenv( const char * name )
 
 int main( void )
 {
-    TESTCASE( strcmp( getenv( "SHELL" ), "/bin/bash" ) == 0 );
-    /* TESTCASE( strcmp( getenv( "SHELL" ), "/bin/sh" ) == 0 ); */
     return TEST_RESULTS;
 }
 
index eb8db3dbd9022f6b80f39881289ed95e3c820d1f..2cf7534b2faf99671408ab044ac56dcb399fe630 100644 (file)
@@ -8,49 +8,19 @@
 
 #include <stdlib.h>
 
-/* This is an example implementation of system() fit for use with POSIX kernels.
+/* This is a stub implementation of getenv
 */
 
-extern int fork( void );
-extern int execve( const char * filename, char * const argv[], char * const envp[] );
-extern int wait( int * status );
-
 int system( const char * string )
 {
-    char const * const argv[] = { "sh", "-c", (char const * const)string, NULL };
-    if ( string != NULL )
-    {
-        int pid = fork();
-        if ( pid == 0 )
-        {
-            execve( "/bin/sh", (char * * const)argv, NULL );
-        }
-        else if ( pid > 0 )
-        {
-            while( wait( NULL ) != pid );
-        }
-    }
     return -1;
 }
 
 #ifdef TEST
 #include <_PDCLIB_test.h>
 
-#define SHELLCOMMAND "echo 'SUCCESS testing system()'"
-
 int main( void )
 {
-    FILE * fh;
-    char buffer[25];
-    buffer[24] = 'x';
-    TESTCASE( ( fh = freopen( testfile, "wb+", stdout ) ) != NULL );
-    TESTCASE( system( SHELLCOMMAND ) );
-    rewind( fh );
-    TESTCASE( fread( buffer, 1, 24, fh ) == 24 );
-    TESTCASE( memcmp( buffer, "SUCCESS testing system()", 24 ) == 0 );
-    TESTCASE( buffer[24] == 'x' );
-    TESTCASE( fclose( fh ) == 0 );
-    TESTCASE( remove( testfile ) == 0 );
     return TEST_RESULTS;
 }
 
index de47aeb501358af370570ff668326a47dc672e62..659053997fc9b7b62a590db93c96a2bcfbea4cb8 100644 (file)
@@ -8,11 +8,7 @@
 
 #ifndef _PDCLIB_FLOAT_H
 #define _PDCLIB_FLOAT_H _PDCLIB_FLOAT_H
-
-#ifndef _PDCLIB_CONFIG_H
-#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H
 #include <_PDCLIB_config.h>
-#endif
 
 #define FLT_ROUNDS      _PDCLIB_FLT_ROUNDS
 #define FLT_EVAL_METHOD _PDCLIB_FLT_EVAL_METHOD
index 9b812c96d66f4dba17fc27b489b9686b4c971446..9f6a1a3abc4252850902d4a94bb158e66361ae02 100644 (file)
@@ -8,11 +8,7 @@
 
 #ifndef _PDCLIB_SIGNAL_H
 #define _PDCLIB_SIGNAL_H _PDCLIB_SIGNAL_H
-
-#ifndef _PDCLIB_CONFIG_H
-#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H
 #include <_PDCLIB_config.h>
-#endif
 
 /* Signals ------------------------------------------------------------------ */
 
index 64cc98dc73411bcc4e854ff936e09ab0d2e76f63..7e66178b96ea124ba029b3651e03dfc8739e976c 100644 (file)
@@ -1,4 +1,5 @@
-/* $Id$ */
+#ifndef _PDCLIB_CONFIG_H
+#define _PDCLIB_CONFIG_H
 
 /* Internal PDCLib configuration <_PDCLIB_config.h>
    (Generic Template)
@@ -170,6 +171,36 @@ struct _PDCLIB_imaxdiv_t
     _PDCLIB_intmax rem;
 };
 
+/* <time.h>: time_t 
+ * The C standard doesn't define what representation of time is stored in 
+ * time_t when returned by time() , but POSIX defines it to be seconds since the
+ * UNIX epoch and most appplications expect that. 
+ *
+ * time_t is also used as the tv_sec member of struct timespec, which *is* 
+ * defined as a linear count of seconds.
+ *
+ * time_t is defined as a "real type", so may be a floating point type, but with
+ * the presence of the nanosecond accurate struct timespec, and with the lack of
+ * any functions for manipulating more accurate values of time_t, this is 
+ * probably not useful.
+ */
+#define _PDCLIB_time  unsigned long long
+
+/* <time.h>: clock_t
+ *
+ * A count of "clock ticks", where the length of a clock tick is unspecified by
+ * the standard. The implementation is required to provide a macro, 
+ * CLOCKS_PER_SEC, which is the number of "clock ticks" which corresponds to one
+ * second.
+ *
+ * clock_t may be any real type (i.e. integral or floating), and its type on
+ * various systems differs. 
+ *
+ * On XSI systems, CLOCKS_PER_SEC must be defined to 1000000
+ */
+#define _PDCLIB_clock double
+#define _PDCLIB_CLOCKS_PER_SEC 1000000
+
 /* -------------------------------------------------------------------------- */
 /* Floating Point                                                             */
 /* -------------------------------------------------------------------------- */
@@ -312,45 +343,103 @@ typedef int _PDCLIB_fd_t;
    If you do not want that kind of translation, you might want to "match" the
    values used by PDCLib with those used by the host OS, as to avoid confusion.
 
-   The standard only defines three distinct errno values: ERANGE, EDOM, and
+   The standard only defines three distinct errno values: ERANGE, EDOM, and
    EILSEQ. The standard leaves it up to "the implementation" whether there are
    any more beyond those three. There is some controversy as to whether errno is
    such a good idea at all, so you might want to come up with a different error
-   reporting facility for your platform. Since errno values beyond the three
-   defined by the standard are not portable anyway (unless you look at POSIX),
-   having your own error reporting facility would not hurt anybody either.
+   reporting facility for your platform. 
+
+   Things used to say "Since errno values beyond the three defined by the 
+   standard are not portable anyway (unless you look at POSIX), having your own
+   error reporting facility would not hurt anybody either." at this point. 
+   However, then somebody birthed C++11 into the world, which copied POSIX's 
+   errno values into C++. Yes, even EINTR. Therefore, this library defines 
+   them. That said, thats nothing stopping you from using your own error 
+   reporting facility for things outside the C library.
+
+   Sometimes the standard says to set errno to indicate an error, but does not 
+   prescribe a value. We will use a value from the following list. If POSIX 
+   defines a value, we use that; otherwise, we use as seems suitable.
+
+   If porting to a system which uses an errno-like reporting system (e.g. a 
+   UNIX), you'll probably want to define them to match what the OS uses
 */
+/* C errno values */
 #define _PDCLIB_ERANGE 1
 #define _PDCLIB_EDOM   2
 #define _PDCLIB_EILSEQ 3
 
-/* The following is not strictly "configuration", but there is no better place
-   to explain it than here.
-
-   PDCLib strives to be as generic as possible, so by default it does NOT define
-   any values beyond the three standard ones above, even where it would have
-   been prudent and convenient to do so. Any errno "caught" from the host OS,
-   and some internal error conditions as well, are all lumped together into the
-   value of '_PDCLIB_ERROR'.
-
-   '_PDCLIB_ERROR' is STRICLY meant as a PLACEHOLDER only.
-
-   You should NEVER ship an adaption of PDCLib still using that particular
-   value. You should NEVER write code that *tests* for that value. Indeed it is
-   not even conforming, since errno values should be defined as beginning with
-   an uppercase 'E', and there is no mechanics in <errno.h> to unmask that
-   particular value (for exactly that reason).
-
-   There also is no error message available for this value through either the
-   strerror() or perror() functions. It is being reported as "unknown" error.
-
-   The idea is that you scan the source of PDCLib for occurrences of this macro
-   and replace _PDCLIB_ERROR with whatever additional errno value you came up
-   with for your platform.
-
-   If you cannot find it within you to do that, tell your clients to check for
-   an errno value larger than zero. That, at least, would be standard compliant
-   (and fully portable).
-*/
-#define _PDCLIB_ERROR  4
-
+/* C++11/POSIX errno values */
+#define _PDCLIB_E2BIG 4
+#define _PDCLIB_ECONNRESET 5
+#define _PDCLIB_EISCONN 6
+#define _PDCLIB_ENOENT 7
+#define _PDCLIB_ENOTRECOVERABLE 8
+#define _PDCLIB_EROFS 9
+#define _PDCLIB_EACCES 10
+#define _PDCLIB_EDEADLK 11
+#define _PDCLIB_EISDIR 12
+#define _PDCLIB_ENOEXEC 13
+#define _PDCLIB_ENOTSOCK 14
+#define _PDCLIB_ESPIPE 15
+#define _PDCLIB_EADDRINUSE 16
+#define _PDCLIB_EDESTADDRREQ 17
+#define _PDCLIB_ELOOP 18
+#define _PDCLIB_ENOLCK 19
+#define _PDCLIB_ENOTSUPP 20
+#define _PDCLIB_ESRCH 21
+#define _PDCLIB_EADDRNOTAVAIL 22
+#define _PDCLIB_EMFILE 23
+#define _PDCLIB_ENOLINK 24
+#define _PDCLIB_ENOTTY 25
+#define _PDCLIB_ETIME 26
+#define _PDCLIB_EAFNOSUPPORT 27
+#define _PDCLIB_EEXIST 28
+#define _PDCLIB_EMLINK 29
+#define _PDCLIB_ENOMEM 30
+#define _PDCLIB_ENXIO 31
+#define _PDCLIB_ETIMEDOUT 32
+#define _PDCLIB_EAGAIN 33
+#define _PDCLIB_EFAULT 34
+#define _PDCLIB_EMSGSIZE 35
+#define _PDCLIB_ENOMSG 36
+#define _PDCLIB_EOPNOTSUPP 37
+#define _PDCLIB_ETXTBSY 38
+#define _PDCLIB_EALREADY 39
+#define _PDCLIB_EFBIG 40
+#define _PDCLIB_ENAMETOOLONG 41
+#define _PDCLIB_ENOPROTOOPT 42
+#define _PDCLIB_EOVERFLOW 43
+#define _PDCLIB_EWOULDBLOCK _PDCLIB_EAGAIN
+#define _PDCLIB_EBADF 44
+#define _PDCLIB_EHOSTUNREACH 45
+#define _PDCLIB_ENETDOWN 46
+#define _PDCLIB_ENOSPC 47
+#define _PDCLIB_EOWNERDEAD 48
+#define _PDCLIB_EXDEV 49
+#define _PDCLIB_EBADMSG 50
+#define _PDCLIB_EIDRM 51
+#define _PDCLIB_ENETRESET 52
+#define _PDCLIB_ENOSR 53
+#define _PDCLIB_EPERM 54
+#define _PDCLIB_EBUSY 55
+#define _PDCLIB_ENETUNREACH 56
+#define _PDCLIB_ENOSTR 57
+#define _PDCLIB_EPIPE 58
+#define _PDCLIB_ECANCELED 59
+#define _PDCLIB_EINPROGRESS 60
+#define _PDCLIB_ENFILE 61
+#define _PDCLIB_ENOSYS 62
+#define _PDCLIB_EPROTO 63
+#define _PDCLIB_ECHILD 64
+#define _PDCLIB_EINTR 65
+#define _PDCLIB_ENOBUFS 66
+#define _PDCLIB_ENOTCONN 67
+#define _PDCLIB_EPROTONOSUPPORT 68
+#define _PDCLIB_ECONNABORTED 69
+#define _PDCLIB_EINVAL 70
+#define _PDCLIB_ENODATA 71
+#define _PDCLIB_ENOTDIR 72
+#define _PDCLIB_EPROTOTYPE 73
+
+#endif
diff --git a/platform/example_64/internals/_PDCLIB_config.h b/platform/example_64/internals/_PDCLIB_config.h
deleted file mode 100644 (file)
index c50281a..0000000
+++ /dev/null
@@ -1,280 +0,0 @@
-/* $Id$ */
-
-/* Internal PDCLib configuration <_PDCLIB_config.h>
-   (Generic Template)
-
-   This file is part of the Public Domain C Library (PDCLib).
-   Permission is granted to use, modify, and / or redistribute at will.
-*/
-
-/* -------------------------------------------------------------------------- */
-/* Misc                                                                       */
-/* -------------------------------------------------------------------------- */
-
-/* The character (sequence) your platform uses as newline.                    */
-#define _PDCLIB_endl "\n"
-
-/* exit() can signal success to the host environment by the value of zero or  */
-/* the constant EXIT_SUCCESS. Failure is signaled by EXIT_FAILURE. Note that  */
-/* any other return value is "implementation-defined", i.e. your environment  */
-/* is not required to handle it gracefully. Set your definitions here.        */
-#define _PDCLIB_SUCCESS 0
-#define _PDCLIB_FAILURE -1
-
-/* qsort() in <stdlib.h> requires a function that swaps two memory areas.     */
-/* Below is a naive implementation that can be improved significantly for     */
-/* specific platforms, e.g. by swapping int instead of char.                  */
-#define _PDCLIB_memswp( i, j, size ) char tmp; do { tmp = *i; *i++ = *j; *j++ = tmp; } while ( --size );
-
-/* Define this to some compiler directive that can be written after the       */
-/* parameter list of a function declaration to indicate the function does     */
-/* never return. If your compiler does not support such a directive, define   */
-/* to nothing. (This is to avoid warnings with the exit functions under GCC.) */
-#define _PDCLIB_NORETURN __attribute__(( noreturn ))
-
-/* -------------------------------------------------------------------------- */
-/* Integers                                                                   */
-/* -------------------------------------------------------------------------- */
-/* Assuming 8-bit char, two's-complement architecture here. 'short' being     */
-/* 16 bit, 'int' being either 16, 32 or 64 bit, 'long' being either 32 or 64  */
-/* bit (but 64 bit only if 'int' is 32 bit), and 'long long' being 64 bit if  */
-/* 'long' is not, 64 or 128 bit otherwise.                                    */
-/* Author is quite willing to support other systems but would like to hear of */
-/* interest in such support and details on the to-be-supported architecture   */
-/* first, before going to lengths about it.                                   */
-/* -------------------------------------------------------------------------- */
-
-/* Comment out (or delete) the line below if your 'char' type is unsigned.    */
-#define _PDCLIB_CHAR_SIGNED 1
-
-/* Width of the integer types short, int, long, and long long, in bytes.      */
-/* SHRT == 2, INT >= SHRT, LONG >= INT >= 4, LLONG >= LONG - check your       */
-/* compiler manuals.                                                          */
-#define _PDCLIB_SHRT_BYTES  2
-#define _PDCLIB_INT_BYTES   4
-#define _PDCLIB_LONG_BYTES  8
-#define _PDCLIB_LLONG_BYTES 8
-
-/* <stdlib.h> defines the div() function family that allows taking quotient   */
-/* and remainder of an integer division in one operation. Many platforms      */
-/* support this in hardware / opcode, and the standard permits ordering of    */
-/* the return structure in any way to fit the hardware. That is why those     */
-/* structs can be configured here.                                            */
-
-struct _PDCLIB_div_t
-{
-    int quot;
-    int rem;
-};
-
-struct _PDCLIB_ldiv_t
-{
-    long int quot;
-    long int rem;
-};
-
-struct _PDCLIB_lldiv_t
-{
-    long long int quot;
-    long long int rem;
-};
-
-/* -------------------------------------------------------------------------- */
-/* <stdint.h> defines a set of integer types that are of a minimum width, and */
-/* "usually fastest" on the system. (If, for example, accessing a single char */
-/* requires the CPU to access a complete int and then mask out the char, the  */
-/* "usually fastest" type of at least 8 bits would be int, not char.)         */
-/* If you do not have information on the relative performance of the types,   */
-/* the standard allows you to define any type that meets minimum width and    */
-/* signedness requirements.                                                   */
-/* The defines below are just configuration for the real typedefs and limit   */
-/* definitions done in <_PDCLIB_int.h>. The uppercase define shall be either  */
-/* SHRT, INT, LONG, or LLONG (telling which values to use for the *_MIN and   */
-/* *_MAX limits); the lowercase define either short, int, long, or long long  */
-/* (telling the actual type to use).                                          */
-/* The third define is the length modifier used for the type in printf() and  */
-/* scanf() functions (used in <inttypes.h>).                                  */
-/* If you require a non-standard datatype to define the "usually fastest"     */
-/* types, PDCLib as-is doesn't support that. Please contact the author with   */
-/* details on your platform in that case, so support can be added.            */
-/* -------------------------------------------------------------------------- */
-
-#define _PDCLIB_FAST8 INT
-#define _PDCLIB_fast8 int
-#define _PDCLIB_FAST8_CONV
-
-#define _PDCLIB_FAST16 INT
-#define _PDCLIB_fast16 int
-#define _PDCLIB_FAST16_CONV
-
-#define _PDCLIB_FAST32 INT
-#define _PDCLIB_fast32 int
-#define _PDCLIB_FAST32_CONV
-
-#define _PDCLIB_FAST64 LONG
-#define _PDCLIB_fast64 long
-#define _PDCLIB_FAST64_CONV l
-
-/* -------------------------------------------------------------------------- */
-/* What follows are a couple of "special" typedefs and their limits. Again,   */
-/* the actual definition of the limits is done in <_PDCLIB_int.h>, and the    */
-/* defines here are merely "configuration". See above for details.            */
-/* -------------------------------------------------------------------------- */
-
-/* The result type of substracting two pointers */
-#define _PDCLIB_ptrdiff long
-#define _PDCLIB_PTRDIFF LONG
-#define _PDCLIB_PTR_CONV l
-
-/* An integer type that can be accessed as atomic entity (think asynchronous
-   interrupts). The type itself is not defined in a freestanding environment,
-   but its limits are. (Don't ask.)
-*/
-#define _PDCLIB_sig_atomic int
-#define _PDCLIB_SIG_ATOMIC INT
-
-/* Result type of the 'sizeof' operator (must be unsigned) */
-#define _PDCLIB_size unsigned long
-#define _PDCLIB_SIZE ULONG
-
-/* Large enough an integer to hold all character codes of the largest supported
-   locale.
-*/
-#define _PDCLIB_wchar unsigned short 
-#define _PDCLIB_WCHAR USHRT
-
-#define _PDCLIB_intptr long
-#define _PDCLIB_INTPTR LONG
-
-/* Largest supported integer type. Implementation note: see _PDCLIB_atomax(). */
-#define _PDCLIB_intmax long long int
-#define _PDCLIB_INTMAX LLONG
-#define _PDCLIB_MAX_CONV ll
-/* You are also required to state the literal suffix for the intmax type      */
-#define _PDCLIB_INTMAX_LITERAL ll
-
-/* <inttypes.h> defines imaxdiv(), which is equivalent to the div() function  */
-/* family (see further above) with intmax_t as basis.                         */
-
-struct _PDCLIB_imaxdiv_t
-{
-    _PDCLIB_intmax quot;
-    _PDCLIB_intmax rem;
-};
-
-/* -------------------------------------------------------------------------- */
-/* Floating Point                                                             */
-/* -------------------------------------------------------------------------- */
-
-/* Whether the implementation rounds toward zero (0), to nearest (1), toward
-   positive infinity (2), or toward negative infinity (3). (-1) signifies
-   indeterminable rounding, any other value implementation-specific rounding.
-*/
-#define _PDCLIB_FLT_ROUNDS -1
-
-/* Whether the implementation uses exact-width precision (0), promotes float
-   to double (1), or promotes float and double to long double (2). (-1)
-   signifies indeterminable behaviour, any other value implementation-specific
-   behaviour.
-*/
-#define _PDCLIB_FLT_EVAL_METHOD -1
-
-/* "Number of the decimal digits (n), such that any floating-point number in the
-   widest supported floating type with p(max) radix (b) digits can be rounded to
-   a floating-point number with (n) decimal digits and back again without change
-   to the value p(max) log(10)b if (b) is a power of 10, [1 + p(max) log(10)b]
-   otherwise."
-   64bit IEC 60559 double format (53bit mantissa) is DECIMAL_DIG 17.
-   80bit IEC 60559 double-extended format (64bit mantissa) is DECIMAL_DIG 21.
-*/
-#define _PDCLIB_DECIMAL_DIG 17
-
-/* -------------------------------------------------------------------------- */
-/* Platform-dependent macros defined by the standard headers.                 */
-/* -------------------------------------------------------------------------- */
-
-/* The offsetof macro
-   Contract: Expand to an integer constant expression of type size_t, which
-   represents the offset in bytes to the structure member from the beginning
-   of the structure. If the specified member is a bitfield, behaviour is
-   undefined.
-   There is no standard-compliant way to do this.
-   This implementation casts an integer zero to 'pointer to type', and then
-   takes the address of member. This is undefined behaviour but should work on
-   most compilers.
-*/
-#define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) )
-
-/* Variable Length Parameter List Handling (<stdarg.h>)
-   No way to cover x86_64 with a generic implementation, as it uses register-
-   based parameter passing. Using the GCC builtins here.
-*/
-typedef __builtin_va_list _PDCLIB_va_list;
-#define _PDCLIB_va_arg( ap, type ) ( __builtin_va_arg( ap, type ) )
-#define _PDCLIB_va_copy( dest, src ) ( __builtin_va_copy( dest, src ) )
-#define _PDCLIB_va_end( ap ) ( __builtin_va_end( ap ) )
-#define _PDCLIB_va_start( ap, parmN ) ( __builtin_va_start( ap, parmN ) )
-
-/* -------------------------------------------------------------------------- */
-/* OS "glue", part 1                                                          */
-/* These are values and data type definitions that you would have to adapt to */
-/* the capabilities and requirements of your OS.                              */
-/* The actual *functions* of the OS interface are declared in _PDCLIB_glue.h. */
-/* -------------------------------------------------------------------------- */
-
-/* Memory management -------------------------------------------------------- */
-
-/* Set this to the page size of your OS. If your OS does not support paging, set
-   to an appropriate value. (Too small, and malloc() will call the kernel too
-   often. Too large, and you will waste memory.)
-*/
-#define _PDCLIB_PAGESIZE 4096
-
-/* Set this to the minimum memory node size. Any malloc() for a smaller size
-   will be satisfied by a malloc() of this size instead (to avoid excessive
-   fragmentation).
-*/
-#define _PDCLIB_MINALLOC 8
-
-/* I/O ---------------------------------------------------------------------- */
-
-/* The type of the file descriptor returned by _PDCLIB_open(). */
-typedef int _PDCLIB_fd_t;
-
-/* The value (of type _PDCLIB_fd_t) returned by _PDCLIB_open() if the operation
-   failed.
-*/
-#define _PDCLIB_NOHANDLE ( (_PDCLIB_fd_t) -1 )
-
-/* The default size for file buffers. Must be at least 256. */
-#define _PDCLIB_BUFSIZ 1024
-
-/* The minimum number of files the implementation can open simultaneously. Must
-   be at least 8. Depends largely on how the bookkeeping is done by fopen() /
-   freopen() / fclose(). The example implementation limits the number of open
-   files only by available memory.
-*/
-#define _PDCLIB_FOPEN_MAX 8
-
-/* Length of the longest filename the implementation guarantees to support. */
-#define _PDCLIB_FILENAME_MAX 128
-
-/* Maximum length of filenames generated by tmpnam(). (See tmpfile.c.) */
-#define _PDCLIB_L_tmpnam 46
-
-/* Number of distinct file names that can be generated by tmpnam(). */
-#define _PDCLIB_TMP_MAX 50
-
-/* The values of SEEK_SET, SEEK_CUR and SEEK_END, used by fseek().
-   Since at least one platform (POSIX) uses the same symbols for its own "seek"
-   function, we use whatever the host defines (if it does define them).
-*/
-#define _PDCLIB_SEEK_SET 0
-#define _PDCLIB_SEEK_CUR 1
-#define _PDCLIB_SEEK_END 2
-
-/* The number of characters that can be buffered with ungetc(). The standard
-   guarantees only one (1); anything larger would make applications relying on
-   this capability dependent on implementation-defined behaviour (not good).
-*/
-#define _PDCLIB_UNGETCBUFSIZE 1
diff --git a/platform/example_cygwin/Makefile b/platform/example_cygwin/Makefile
deleted file mode 100644 (file)
index 267970f..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-# $Id$
-
-# This is where you chose which platform to compile for (see 'make links' / './platform')
-PLATFORM := example_cygwin
-
-# This is a list of all non-source files that are part of the distribution.
-AUXFILES := Makefile Readme.txt
-
-# Directories belonging to the project
-PROJDIRS := functions includes internals
-# All source files of the project
-SRCFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.c")
-# All header files of the project
-HDRFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.h")
-# All .c files in functions/_PDCLIB that do not have a regression test driver
-INTFILES := _Exit atomax digits open print scan remove rename seed stdinit strtox_main strtox_prelim cleanstream fflush filemode eol errno seek prepread prepwrite allocpages
-# All object files in the library
-OBJFILES := $(patsubst %.c,%.o,$(SRCFILES))
-# All test drivers (.t)
-TSTFILES := $(patsubst %.c,%.t,$(SRCFILES))
-# All regression test drivers (.r)
-REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%.r,$(INTFILES)),$(patsubst %.c,%.r,$(SRCFILES)))
-# All dependency files (.d)
-DEPFILES := $(patsubst %.c,%.d,$(SRCFILES))
-# All files belonging to the source distribution
-ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
-
-# All files in platform/$(PLATFORM)/functions/_PDCLIB (for development only)
-PATCHFILES1 := $(shell ls platform/$(PLATFORM)/functions/_PDCLIB/*.c)
-# All files in platform/$(PLATFORM)/functions/stdlib (for development only)
-PATCHFILES2 := $(shell ls platform/$(PLATFORM)/functions/stdlib/*.c)
-# All files in platform/$(PLATFORM)/functions/stdio (for development only)
-PATCHFILES3 := $(shell ls platform/$(PLATFORM)/functions/stdio/*.c)
-
-WARNINGS := -Wall -Wextra -pedantic -Wno-unused-parameter -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -fno-builtin 
-CFLAGS := -g -std=gnu99 -I./internals $(WARNINGS) $(USERFLAGS)
-
-.PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help
-
-all: pdclib.a testdrivers regtestdrivers
-       @echo
-       @echo "========================"
-       @echo "Executing library tests:"
-       @echo "========================"
-       @echo
-       @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed"
-       @echo
-       @echo "==========================="
-       @echo "Executing regression tests:"
-       @echo "==========================="
-       @echo
-       @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed"
-
-pdclib.a: $(OBJFILES)
-       @echo " AR      $@"
-       @ar rc pdclib.a $?
-       @echo
-
-test: functions/$(FILE)
-       functions/$(FILE)
-
-tests: testdrivers
-       -@rc=0; count=0; failed=""; for file in $(TSTFILES); do echo " TST      $$file"; ./$$file; test=$$?; if [ $$test != 0 ]; then rc=`expr $$rc + $$test`; failed="$$failed $$file"; fi; count=`expr $$count + 1`; done; echo; echo "Tests executed (linking PDCLib): $$count  Tests failed: $$rc"; echo; for file in $$failed; do echo "Failed: $$file"; done; echo
-
-testdrivers: $(TSTFILES)
-       @echo
-
-regtests: regtestdrivers
-       -@rc=0; count=0; failed=""; for file in $(REGFILES); do echo " RTST     $$file"; ./$$file; test=$$?; if [ $$test != 0 ]; then rc=`expr $$rc + $$test`; failed="$$failed $$file"; fi; count=`expr $$count + 1`; done; echo; echo "Tests executed (linking system libc): $$count  Tests failed: $$rc"; echo; for file in $$failed; do echo "Failed: $$file"; done; echo
-
-regtestdrivers: $(REGFILES)
-       @echo
-
--include $(DEPFILES)
-
-clean:
-       @for file in $(OBJFILES) $(DEPFILES) $(TSTFILES) $(REGFILES) pdclib.a pdclib.tgz; do if [ -f $$file ]; then rm $$file; fi; done
-
-srcdist:
-       @tar czf pdclib.tgz $(ALLFILES)
-
-todos:
-       -@for file in $(ALLFILES); do grep -H TODO $$file; done; true
-
-fixmes:
-       -@for file in $(ALLFILES); do grep -H FIXME $$file; done; true
-
-find:
-       @find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND
-
-links:
-       @echo "Linking platform/$(PLATFORM)..."
-       @cd internals && ln -s ../platform/$(PLATFORM)/internals/_PDCLIB_config.h
-       @cd includes && ln -s ../platform/$(PLATFORM)/includes/float.h
-       @cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done
-       @cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done
-       @cd functions/stdio && for file in $(PATCHFILES3); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done
-
-unlink:
-       @echo "Unlinking platform files..."
-       @if [ -f internals/_PDCLIB_config.h ]; then rm internals/_PDCLIB_config.h; fi
-       @if [ -f includes/float.h ]; then rm includes/float.h; fi
-       @cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done
-       @cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done
-       @cd functions/stdio && for file in $(PATCHFILES3); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done
-
-help:
-       @echo "Available make targets:"
-       @echo
-       @echo "all              - build pdclib.a"
-       @echo "clean            - remove all object files, dependency files and test drivers"
-       @echo "srcdist          - build pdclib.tgz (source tarball)"
-       @echo "test             - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)"
-       @echo "tests            - build and run test drivers (link pdclib.a)"
-       @echo "  testdrivers    - build but do not run test drivers"
-       @echo "regtests         - build and run regression test drivers (link system clib)"
-       @echo "  regtestdrivers - build but do not run regression test drivers"
-       @echo "todos            - list all TODO comments in the sources"
-       @echo "fixmes           - list all FIXME comments in the sources"
-       @echo "find             - find a phrase in the sources (Usage: FIND=\"phrase\" make find)"
-       @echo "links            - link platform files (development only)"
-       @echo "unlink           - remove links to platform files (development only)"
-       @echo "%.o              - build an individual object file"
-       @echo "%.t              - build an individual test driver"
-       @echo "%.r              - build an individual regression test driver"
-       @echo "help             - print this list"
-       @echo
-       @echo "Any additional compiler flags you want to use can be passed as USERFLAGS"
-       @echo "(Usage: USERFLAGS=\"flags\" make [...])."
-
-%.o: %.c Makefile
-       @echo " CC      $(patsubst functions/%,%,$@)"
-       @$(CC) $(CFLAGS) -MMD -MP -MT "$*.d $*.t" -I./includes -c $< -o $@
-
-%.t: %.c Makefile pdclib.a
-       @echo " CC      $(patsubst functions/%,%,$@)"
-       @$(CC) $(CFLAGS) -DTEST -I./includes $< pdclib.a -o $@
-
-%.r: %.c Makefile
-       @echo " CC      $(patsubst functions/%,%,$@)"
-       @$(CC) $(CFLAGS) -Wno-format -DTEST -DREGTEST $< -o $@
-
diff --git a/platform/example_cygwin/functions/_PDCLIB/stdinit.c b/platform/example_cygwin/functions/_PDCLIB/stdinit.c
deleted file mode 100644 (file)
index af37f06..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/* $Id$ */
-
-/* _PDCLIB_stdinit
-
-   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 initialization of stdin, stdout and stderr to the integer
-   file descriptors 0, 1, and 2, respectively. This applies for a great variety
-   of operating systems, including POSIX compliant ones.
-*/
-
-#include <stdio.h>
-
-#ifndef REGTEST
-
-/* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file
-   descriptors 0, 1, and 2 respectively.
-*/
-/* TODO: This is proof-of-concept, requires finetuning. */
-static char _PDCLIB_sin_buffer[BUFSIZ];
-static char _PDCLIB_sout_buffer[BUFSIZ];
-static char _PDCLIB_serr_buffer[BUFSIZ];
-
-static unsigned char _PDCLIB_sin_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
-static unsigned char _PDCLIB_sout_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
-static unsigned char _PDCLIB_serr_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
-
-/* FIXME: serr should handle one character. Buffering on out / in? */
-static struct _PDCLIB_file_t _PDCLIB_serr = { 2, _PDCLIB_serr_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_serr_ungetbuf, _IONBF | _PDCLIB_FWRITE, NULL, NULL };
-static struct _PDCLIB_file_t _PDCLIB_sout = { 1, _PDCLIB_sout_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_sout_ungetbuf, _IOLBF | _PDCLIB_FWRITE, NULL, &_PDCLIB_serr };
-static struct _PDCLIB_file_t _PDCLIB_sin  = { 0, _PDCLIB_sin_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_sin_ungetbuf, _IOLBF | _PDCLIB_FREAD, NULL, &_PDCLIB_sout };
-
-struct _PDCLIB_file_t * stdin  = &_PDCLIB_sin;
-struct _PDCLIB_file_t * stdout = &_PDCLIB_sout;
-struct _PDCLIB_file_t * stderr = &_PDCLIB_serr;
-
-/* FIXME: This approach is a possible attack vector. */
-struct _PDCLIB_file_t * _PDCLIB_filelist = &_PDCLIB_sin;
-
-#endif
-
-#ifdef TEST
-#include <_PDCLIB_test.h>
-
-int main( void )
-{
-    /* Testing covered by several other testdrivers using stdin / stdout / 
-       stderr.
-    */
-    return TEST_RESULTS;
-}
-
-#endif
diff --git a/platform/example_cygwin/functions/stdio/tmpfile.c b/platform/example_cygwin/functions/stdio/tmpfile.c
deleted file mode 100644 (file)
index 3049260..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/* $Id$ */
-
-/* tmpfile( void )
-
-   This file is part of the Public Domain C Library (PDCLib).
-   Permission is granted to use, modify, and / or redistribute at will.
-*/
-
-#include <stdio.h>
-
-#ifndef REGTEST
-
-struct _PDCLIB_file_t * tmpfile( void )
-{
-    /* TODO: Implement */
-    return NULL;
-}
-
-#endif
-
-#ifdef TEST
-#include <_PDCLIB_test.h>
-
-int main( void )
-{
-    FILE * fh;
-    char filename[ L_tmpnam ];
-    FILE * fhtest;
-    TESTCASE( ( fh = tmpfile() ) != NULL );
-    TESTCASE( fputc( 'x', fh ) == 'x' );
-    /* Checking that file is actually there */
-    TESTCASE_NOREG( strcpy( filename, fh->filename ) == filename );
-    TESTCASE_NOREG( ( fhtest = fopen( filename, "r" ) ) != NULL );
-    TESTCASE_NOREG( fclose( fhtest ) == 0 );
-    /* Closing tmpfile */
-    TESTCASE( fclose( fh ) == 0 );
-    /* Checking that file was deleted */
-    TESTCASE_NOREG( fopen( filename, "r" ) == NULL );
-    return TEST_RESULTS;
-}
-
-#endif
similarity index 94%
rename from platform/example_cygwin/functions/_PDCLIB/allocpages.c
rename to platform/posix/functions/_PDCLIB/allocpages.c
index 5998c405abe880a789b08de4c25599f10a7f7b8a..435e8c64b8840fa7c429f2faadaf9d81caca3d8a 100644 (file)
@@ -13,6 +13,7 @@
 #include <stdint.h>
 #include <stddef.h>
 
+int brk( void * );
 void * sbrk( intptr_t );
 
 #ifndef _PDCLIB_GLUE_H
@@ -44,7 +45,7 @@ void * _PDCLIB_allocpages( int const n )
     /* increasing or decreasing heap - standard operation */
     void * oldbreak = membreak;
     membreak = (void *)( (char *)membreak + ( n * _PDCLIB_PAGESIZE ) );
-    if ( sbrk( (char*)membreak - (char*)oldbreak ) == membreak )
+    if ( brk( membreak ) == 0 )
     {
         /* successful */
         return oldbreak;
@@ -62,6 +63,8 @@ void * _PDCLIB_allocpages( int const n )
 
 int main( void )
 {
+#ifndef REGTEST
+    {
     char * startbreak = sbrk( 0 );
     TESTCASE( _PDCLIB_allocpages( 0 ) );
     TESTCASE( ( (char *)sbrk( 0 ) - startbreak ) <= _PDCLIB_PAGESIZE );
@@ -72,6 +75,9 @@ int main( void )
     TESTCASE( sbrk( 0 ) == startbreak + ( 6 * _PDCLIB_PAGESIZE ) );
     TESTCASE( _PDCLIB_allocpages( -3 ) );
     TESTCASE( sbrk( 0 ) == startbreak + ( 3 * _PDCLIB_PAGESIZE ) );
+    }
+#endif
+    return TEST_RESULTS;
 }
 
 #endif
diff --git a/platform/posix/functions/_PDCLIB/allocpages.o b/platform/posix/functions/_PDCLIB/allocpages.o
new file mode 100644 (file)
index 0000000..0b2200a
Binary files /dev/null and b/platform/posix/functions/_PDCLIB/allocpages.o differ
diff --git a/platform/posix/functions/_PDCLIB/close.o b/platform/posix/functions/_PDCLIB/close.o
new file mode 100644 (file)
index 0000000..eb9b9d5
Binary files /dev/null and b/platform/posix/functions/_PDCLIB/close.o differ
similarity index 98%
rename from platform/example_cygwin/functions/_PDCLIB/fillbuffer.c
rename to platform/posix/functions/_PDCLIB/fillbuffer.c
index 29808b2b6f973a39135250e1364122ebd1dd0d9c..1d450259e55ee8721b3a92b0172ec8a77cd20869 100644 (file)
@@ -31,6 +31,7 @@ int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream )
         {
             /* TODO: Text stream conversion here */
         }
+        stream->pos.offset += rc;
         stream->bufend = rc;
         stream->bufidx = 0;
         return 0;
similarity index 97%
rename from platform/example_cygwin/functions/_PDCLIB/open.c
rename to platform/posix/functions/_PDCLIB/open.c
index 4e7d2b979369b6d000d946907efe3f9bf862a53a..2098dd360a866b65db4a7f9a5c5a249d4f72020c 100644 (file)
@@ -26,8 +26,6 @@ int _PDCLIB_open( char const * const filename, unsigned int mode )
 {
     /* This is an example implementation of _PDCLIB_open() fit for use with
        POSIX kernels.
-       FIXME: The permissions of newly created files should not be hardcoded
-       here.
     */
     int osmode;
     switch ( mode & ( _PDCLIB_FREAD | _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_FRW ) )
@@ -56,7 +54,7 @@ int _PDCLIB_open( char const * const filename, unsigned int mode )
     int rc;
     if ( osmode & O_CREAT )
     {
-        rc = open( filename, osmode, S_IRUSR | S_IWUSR );
+        rc = open( filename, osmode, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH );
     }
     else
     {
similarity index 95%
rename from platform/example_cygwin/functions/_PDCLIB/rename.c
rename to platform/posix/functions/_PDCLIB/rename.c
index db38afdfc91898a8fbf445c08403ea1248f8b07c..a37eeb3464ed74a22d30a4ee4fbd7280479b1a8c 100644 (file)
@@ -111,12 +111,14 @@ int main( void )
     TESTCASE( fputc( 'x', file ) == 'x' );
     TESTCASE( fclose( file ) == 0 );
     /* check that file 1 exists */
-    TESTCASE( fopen( testfile1, "r" ) != NULL );
+    TESTCASE( ( file = fopen( testfile1, "r" ) ) != NULL );
+    TESTCASE( fclose( file ) == 0 );
     /* rename file 1 to file 2 */
     TESTCASE( _PDCLIB_rename( testfile1, testfile2 ) == 0 );
     /* check that file 2 exists, file 1 does not */
     TESTCASE( fopen( testfile1, "r" ) == NULL );
-    TESTCASE( fopen( testfile2, "r" ) != NULL );
+    TESTCASE( ( file = fopen( testfile2, "r" ) ) != NULL );
+    TESTCASE( fclose( file ) == 0 );
     /* create another file 1 */
     TESTCASE( ( file = fopen( testfile1, "w" ) ) != NULL );
     TESTCASE( fputc( 'x', file ) == 'x' );
similarity index 76%
rename from platform/example_cygwin/functions/_PDCLIB/seek.c
rename to platform/posix/functions/_PDCLIB/seek.c
index 449a62a459cfd23a0a847470483993e373049775..755abe2cb1eb9393a943356007f9071a69b9f2de 100644 (file)
@@ -15,7 +15,7 @@
 
 #include "/usr/include/errno.h"
 
-extern int lseek( int fd, int offset, int whence );
+extern _PDCLIB_int64_t lseek64( int fd, _PDCLIB_int64_t offset, int whence );
 
 _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence )
 {
@@ -27,11 +27,14 @@ _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t of
             /* EMPTY - OK */
             break;
         default:
+            /* See comments on implementation-defined errno values in
+               <_PDCLIB_config.h>.
+            */
             _PDCLIB_errno = _PDCLIB_ERROR;
             return EOF;
             break;
     }
-    _PDCLIB_int64_t rc = lseek( stream->handle, offset, whence );
+    _PDCLIB_int64_t rc = lseek64( stream->handle, offset, whence );
     if ( rc != EOF )
     {
         stream->ungetidx = 0;
@@ -42,11 +45,11 @@ _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t of
     }
     switch ( errno )
     {
-        /* See comments on implementation-defined errno values in
-           <_PDCLIB_config.h>.
-        */
         case EBADF:
         case EFAULT:
+            /* See comments on implementation-defined errno values in
+               <_PDCLIB_config.h>.
+            */
             _PDCLIB_errno = _PDCLIB_ERROR;
             break;
         default:
diff --git a/platform/posix/functions/_PDCLIB/stdinit.c b/platform/posix/functions/_PDCLIB/stdinit.c
new file mode 100644 (file)
index 0000000..2554e9f
--- /dev/null
@@ -0,0 +1,355 @@
+/* $Id$ */
+
+/* _PDCLIB_stdinit
+
+   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 initialization of stdin, stdout and stderr to the integer
+   file descriptors 0, 1, and 2, respectively. This applies for a great variety
+   of operating systems, including POSIX compliant ones.
+*/
+
+#include <stdio.h>
+#include <locale.h>
+#include <limits.h>
+
+#ifndef REGTEST
+
+/* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file
+   descriptors 0, 1, and 2 respectively.
+*/
+/* TODO: This is proof-of-concept, requires finetuning. */
+static char _PDCLIB_sin_buffer[BUFSIZ];
+static char _PDCLIB_sout_buffer[BUFSIZ];
+static char _PDCLIB_serr_buffer[BUFSIZ];
+
+static unsigned char _PDCLIB_sin_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
+static unsigned char _PDCLIB_sout_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
+static unsigned char _PDCLIB_serr_ungetbuf[_PDCLIB_UNGETCBUFSIZE];
+
+static struct _PDCLIB_file_t _PDCLIB_serr = { 2, _PDCLIB_serr_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_serr_ungetbuf, _IONBF | _PDCLIB_FWRITE | _PDCLIB_STATIC, NULL, NULL };
+static struct _PDCLIB_file_t _PDCLIB_sout = { 1, _PDCLIB_sout_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_sout_ungetbuf, _IOLBF | _PDCLIB_FWRITE | _PDCLIB_STATIC, NULL, &_PDCLIB_serr };
+static struct _PDCLIB_file_t _PDCLIB_sin  = { 0, _PDCLIB_sin_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, _PDCLIB_sin_ungetbuf, _IOLBF | _PDCLIB_FREAD | _PDCLIB_STATIC, NULL, &_PDCLIB_sout };
+
+struct _PDCLIB_file_t * stdin  = &_PDCLIB_sin;
+struct _PDCLIB_file_t * stdout = &_PDCLIB_sout;
+struct _PDCLIB_file_t * stderr = &_PDCLIB_serr;
+
+/* FIXME: This approach is a possible attack vector. */
+struct _PDCLIB_file_t * _PDCLIB_filelist = &_PDCLIB_sin;
+
+/* "C" locale - defaulting to ASCII-7.
+   1 kByte (+ 4 byte) of <ctype.h> data.
+   Each line: flags, lowercase, uppercase, collation.
+*/
+static struct _PDCLIB_ctype_t _ctype[] = {
+    { /* EOF */    0,    0,    0,    0 },
+    { /* NUL */ _PDCLIB_CTYPE_CNTRL,                                             0x00, 0x00, 0x00 },
+    { /* SOH */ _PDCLIB_CTYPE_CNTRL,                                             0x01, 0x01, 0x01 },
+    { /* STX */ _PDCLIB_CTYPE_CNTRL,                                             0x02, 0x02, 0x02 },
+    { /* ETX */ _PDCLIB_CTYPE_CNTRL,                                             0x03, 0x03, 0x03 },
+    { /* EOT */ _PDCLIB_CTYPE_CNTRL,                                             0x04, 0x04, 0x04 },
+    { /* ENQ */ _PDCLIB_CTYPE_CNTRL,                                             0x05, 0x05, 0x05 },
+    { /* ACK */ _PDCLIB_CTYPE_CNTRL,                                             0x06, 0x06, 0x06 },
+    { /* BEL */ _PDCLIB_CTYPE_CNTRL,                                             0x07, 0x07, 0x07 },
+    { /*  BS */ _PDCLIB_CTYPE_CNTRL,                                             0x08, 0x08, 0x08 },
+    { /*  HT */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_BLANK | _PDCLIB_CTYPE_SPACE, 0x09, 0x09, 0x09 },
+    { /*  LF */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE,                       0x0A, 0x0A, 0x0A },
+    { /*  VT */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE,                       0x0B, 0x0B, 0x0B },
+    { /*  FF */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE,                       0x0C, 0x0C, 0x0C },
+    { /*  CR */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE,                       0x0D, 0x0D, 0x0D },
+    { /*  SO */ _PDCLIB_CTYPE_CNTRL,                                             0x0E, 0x0E, 0x0E },
+    { /*  SI */ _PDCLIB_CTYPE_CNTRL,                                             0x0F, 0x0F, 0x0F },
+    { /* DLE */ _PDCLIB_CTYPE_CNTRL,                                             0x10, 0x10, 0x10 },
+    { /* DC1 */ _PDCLIB_CTYPE_CNTRL,                                             0x11, 0x11, 0x11 },
+    { /* DC2 */ _PDCLIB_CTYPE_CNTRL,                                             0x12, 0x12, 0x12 },
+    { /* DC3 */ _PDCLIB_CTYPE_CNTRL,                                             0x13, 0x13, 0x13 },
+    { /* DC4 */ _PDCLIB_CTYPE_CNTRL,                                             0x14, 0x14, 0x14 },
+    { /* NAK */ _PDCLIB_CTYPE_CNTRL,                                             0x15, 0x15, 0x15 },
+    { /* SYN */ _PDCLIB_CTYPE_CNTRL,                                             0x16, 0x16, 0x16 },
+    { /* ETB */ _PDCLIB_CTYPE_CNTRL,                                             0x17, 0x17, 0x17 },
+    { /* CAN */ _PDCLIB_CTYPE_CNTRL,                                             0x18, 0x18, 0x18 },
+    { /*  EM */ _PDCLIB_CTYPE_CNTRL,                                             0x19, 0x19, 0x19 },
+    { /* SUB */ _PDCLIB_CTYPE_CNTRL,                                             0x1A, 0x1A, 0x1A },
+    { /* ESC */ _PDCLIB_CTYPE_CNTRL,                                             0x1B, 0x1B, 0x1B },
+    { /*  FS */ _PDCLIB_CTYPE_CNTRL,                                             0x1C, 0x1C, 0x1C },
+    { /*  GS */ _PDCLIB_CTYPE_CNTRL,                                             0x1D, 0x1D, 0x1D },
+    { /*  RS */ _PDCLIB_CTYPE_CNTRL,                                             0x1E, 0x1E, 0x1E },
+    { /*  US */ _PDCLIB_CTYPE_CNTRL,                                             0x1F, 0x1F, 0x1F },
+    { /*  SP */ _PDCLIB_CTYPE_BLANK | _PDCLIB_CTYPE_SPACE,                       0x20, 0x20, 0x20 },
+    { /* '!' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x21, 0x21, 0x21 },
+    { /* '"' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x22, 0x22, 0x22 },
+    { /* '#' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x23, 0x23, 0x23 },
+    { /* '$' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x24, 0x24, 0x24 },
+    { /* '%' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x25, 0x25, 0x25 },
+    { /* '&' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x26, 0x26, 0x26 },
+    { /* ''' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x27, 0x27, 0x27 },
+    { /* '(' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x28, 0x28, 0x28 },
+    { /* ')' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x29, 0x29, 0x29 },
+    { /* '*' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x2A, 0x2A, 0x2A },
+    { /* '+' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x2B, 0x2B, 0x2B },
+    { /* ',' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x2C, 0x2C, 0x2C },
+    { /* '-' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x2D, 0x2D, 0x2D },
+    { /* '.' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x2E, 0x2E, 0x2E },
+    { /* '/' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x2F, 0x2F, 0x2F },
+    { /* '0' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x30, 0x30, 0x30 },
+    { /* '1' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x31, 0x31, 0x31 },
+    { /* '2' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x32, 0x32, 0x32 },
+    { /* '3' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x33, 0x33, 0x33 },
+    { /* '4' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x34, 0x34, 0x34 },
+    { /* '5' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x35, 0x35, 0x35 },
+    { /* '6' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x36, 0x36, 0x36 },
+    { /* '7' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x37, 0x37, 0x37 },
+    { /* '8' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x38, 0x38, 0x38 },
+    { /* '9' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_DIGIT | _PDCLIB_CTYPE_XDIGT, 0x39, 0x39, 0x39 },
+    { /* ':' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x3A, 0x3A, 0x3A },
+    { /* ';' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x3B, 0x3B, 0x3B },
+    { /* '<' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x3C, 0x3C, 0x3C },
+    { /* '=' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x3D, 0x3D, 0x3D },
+    { /* '>' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x3E, 0x3E, 0x3E },
+    { /* '?' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x3F, 0x3F, 0x3F },
+    { /* '@' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x40, 0x40, 0x40 },
+    { /* 'A' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x41, 0x61, 0x41 },
+    { /* 'B' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x42, 0x62, 0x42 },
+    { /* 'C' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x43, 0x63, 0x43 },
+    { /* 'D' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x44, 0x64, 0x44 },
+    { /* 'E' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x45, 0x65, 0x45 },
+    { /* 'F' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER | _PDCLIB_CTYPE_XDIGT, 0x46, 0x66, 0x46 },
+    { /* 'G' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x47, 0x67, 0x47 },
+    { /* 'H' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x48, 0x68, 0x48 },
+    { /* 'I' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x49, 0x69, 0x49 },
+    { /* 'J' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4A, 0x6A, 0x4A },
+    { /* 'K' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4B, 0x6B, 0x4B },
+    { /* 'L' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4C, 0x6C, 0x4C },
+    { /* 'M' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4D, 0x6D, 0x4D },
+    { /* 'N' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4E, 0x6E, 0x4E },
+    { /* 'O' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4F, 0x6F, 0x4F },
+    { /* 'P' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x50, 0x70, 0x50 },
+    { /* 'Q' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x51, 0x71, 0x51 },
+    { /* 'R' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x52, 0x72, 0x52 },
+    { /* 'S' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x53, 0x73, 0x53 },
+    { /* 'T' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x54, 0x74, 0x54 },
+    { /* 'U' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x55, 0x75, 0x55 },
+    { /* 'V' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x56, 0x76, 0x56 },
+    { /* 'W' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x57, 0x77, 0x57 },
+    { /* 'X' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x58, 0x78, 0x58 },
+    { /* 'Y' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x59, 0x79, 0x59 },
+    { /* 'Z' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x5A, 0x7A, 0x5A },
+    { /* '[' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x5B, 0x5B, 0x5B },
+    { /* '\' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x5C, 0x5C, 0x5C },
+    { /* ']' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x5D, 0x5D, 0x5D },
+    { /* '^' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x5E, 0x5E, 0x5E },
+    { /* '_' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x5F, 0x5F, 0x5F },
+    { /* '`' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x60, 0x60, 0x60 },
+    { /* 'a' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x41, 0x61, 0x61 },
+    { /* 'b' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x42, 0x62, 0x62 },
+    { /* 'c' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x43, 0x63, 0x63 },
+    { /* 'd' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x44, 0x64, 0x64 },
+    { /* 'e' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x45, 0x65, 0x65 },
+    { /* 'f' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER | _PDCLIB_CTYPE_XDIGT, 0x46, 0x66, 0x66 },
+    { /* 'g' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x47, 0x67, 0x67 },
+    { /* 'h' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x48, 0x68, 0x68 },
+    { /* 'i' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x49, 0x69, 0x69 },
+    { /* 'j' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4A, 0x6A, 0x6A },
+    { /* 'k' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4B, 0x6B, 0x6B },
+    { /* 'l' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4C, 0x6C, 0x6C },
+    { /* 'm' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4D, 0x6D, 0x6D },
+    { /* 'n' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4E, 0x6E, 0x6E },
+    { /* 'o' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4F, 0x6F, 0x6F },
+    { /* 'p' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x50, 0x70, 0x70 },
+    { /* 'q' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x51, 0x71, 0x71 },
+    { /* 'r' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x52, 0x72, 0x72 },
+    { /* 's' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x53, 0x73, 0x73 },
+    { /* 't' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x54, 0x74, 0x74 },
+    { /* 'u' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x55, 0x75, 0x75 },
+    { /* 'v' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x56, 0x76, 0x76 },
+    { /* 'w' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x57, 0x77, 0x77 },
+    { /* 'x' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x58, 0x78, 0x78 },
+    { /* 'y' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x59, 0x79, 0x79 },
+    { /* 'z' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x5A, 0x7A, 0x7A },
+    { /* '{' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x7B, 0x7B, 0x7B },
+    { /* '|' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x7C, 0x7C, 0x7C },
+    { /* '}' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x7D, 0x7D, 0x7D },
+    { /* '~' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT,                       0x7E, 0x7E, 0x7E },
+    { /* DEL */ _PDCLIB_CTYPE_CNTRL,                                             0x7F, 0x7F, 0x7F },
+    { 0x00, 0x80, 0x80, 0x80 },
+    { 0x00, 0x81, 0x81, 0x81 },
+    { 0x00, 0x82, 0x82, 0x82 },
+    { 0x00, 0x83, 0x83, 0x83 },
+    { 0x00, 0x84, 0x84, 0x84 },
+    { 0x00, 0x85, 0x85, 0x85 },
+    { 0x00, 0x86, 0x86, 0x86 },
+    { 0x00, 0x87, 0x87, 0x87 },
+    { 0x00, 0x88, 0x88, 0x88 },
+    { 0x00, 0x89, 0x89, 0x89 },
+    { 0x00, 0x8A, 0x8A, 0x8A },
+    { 0x00, 0x8B, 0x8B, 0x8B },
+    { 0x00, 0x8C, 0x8C, 0x8C },
+    { 0x00, 0x8D, 0x8D, 0x8D },
+    { 0x00, 0x8E, 0x8E, 0x8E },
+    { 0x00, 0x8F, 0x8F, 0x8F },
+    { 0x00, 0x90, 0x90, 0x90 },
+    { 0x00, 0x91, 0x91, 0x91 },
+    { 0x00, 0x92, 0x92, 0x92 },
+    { 0x00, 0x93, 0x93, 0x93 },
+    { 0x00, 0x94, 0x94, 0x94 },
+    { 0x00, 0x95, 0x95, 0x95 },
+    { 0x00, 0x96, 0x96, 0x96 },
+    { 0x00, 0x97, 0x97, 0x97 },
+    { 0x00, 0x98, 0x98, 0x98 },
+    { 0x00, 0x99, 0x99, 0x99 },
+    { 0x00, 0x9A, 0x9A, 0x9A },
+    { 0x00, 0x9B, 0x9B, 0x9B },
+    { 0x00, 0x9C, 0x9C, 0x9C },
+    { 0x00, 0x9D, 0x9D, 0x9D },
+    { 0x00, 0x9E, 0x9E, 0x9E },
+    { 0x00, 0x9F, 0x9F, 0x9F },
+    { 0x00, 0xA0, 0xA0, 0xA0 },
+    { 0x00, 0xA1, 0xA1, 0xA1 },
+    { 0x00, 0xA2, 0xA2, 0xA2 },
+    { 0x00, 0xA3, 0xA3, 0xA3 },
+    { 0x00, 0xA4, 0xA4, 0xA4 },
+    { 0x00, 0xA5, 0xA5, 0xA5 },
+    { 0x00, 0xA6, 0xA6, 0xA6 },
+    { 0x00, 0xA7, 0xA7, 0xA7 },
+    { 0x00, 0xA8, 0xA8, 0xA8 },
+    { 0x00, 0xA9, 0xA9, 0xA9 },
+    { 0x00, 0xAA, 0xAA, 0xAA },
+    { 0x00, 0xAB, 0xAB, 0xAB },
+    { 0x00, 0xAC, 0xAC, 0xAC },
+    { 0x00, 0xAD, 0xAD, 0xAD },
+    { 0x00, 0xAE, 0xAE, 0xAE },
+    { 0x00, 0xAF, 0xAF, 0xAF },
+    { 0x00, 0xB0, 0xB0, 0xB0 },
+    { 0x00, 0xB1, 0xB1, 0xB1 },
+    { 0x00, 0xB2, 0xB2, 0xB2 },
+    { 0x00, 0xB3, 0xB3, 0xB3 },
+    { 0x00, 0xB4, 0xB4, 0xB4 },
+    { 0x00, 0xB5, 0xB5, 0xB5 },
+    { 0x00, 0xB6, 0xB6, 0xB6 },
+    { 0x00, 0xB7, 0xB7, 0xB7 },
+    { 0x00, 0xB8, 0xB8, 0xB8 },
+    { 0x00, 0xB9, 0xB9, 0xB9 },
+    { 0x00, 0xBA, 0xBA, 0xBA },
+    { 0x00, 0xBB, 0xBB, 0xBB },
+    { 0x00, 0xBC, 0xBC, 0xBC },
+    { 0x00, 0xBD, 0xBD, 0xBD },
+    { 0x00, 0xBE, 0xBE, 0xBE },
+    { 0x00, 0xBF, 0xBF, 0xBF },
+    { 0x00, 0xC0, 0xC0, 0xC0 },
+    { 0x00, 0xC1, 0xC1, 0xC1 },
+    { 0x00, 0xC2, 0xC2, 0xC2 },
+    { 0x00, 0xC3, 0xC3, 0xC3 },
+    { 0x00, 0xC4, 0xC4, 0xC4 },
+    { 0x00, 0xC5, 0xC5, 0xC5 },
+    { 0x00, 0xC6, 0xC6, 0xC6 },
+    { 0x00, 0xC7, 0xC7, 0xC7 },
+    { 0x00, 0xC8, 0xC8, 0xC8 },
+    { 0x00, 0xC9, 0xC9, 0xC9 },
+    { 0x00, 0xCA, 0xCA, 0xCA },
+    { 0x00, 0xCB, 0xCB, 0xCB },
+    { 0x00, 0xCC, 0xCC, 0xCC },
+    { 0x00, 0xCD, 0xCD, 0xCD },
+    { 0x00, 0xCE, 0xCE, 0xCE },
+    { 0x00, 0xCF, 0xCF, 0xCF },
+    { 0x00, 0xD0, 0xD0, 0xD0 },
+    { 0x00, 0xD1, 0xD1, 0xD1 },
+    { 0x00, 0xD2, 0xD2, 0xD2 },
+    { 0x00, 0xD3, 0xD3, 0xD3 },
+    { 0x00, 0xD4, 0xD4, 0xD4 },
+    { 0x00, 0xD5, 0xD5, 0xD5 },
+    { 0x00, 0xD6, 0xD6, 0xD6 },
+    { 0x00, 0xD7, 0xD7, 0xD7 },
+    { 0x00, 0xD8, 0xD8, 0xD8 },
+    { 0x00, 0xD9, 0xD9, 0xD9 },
+    { 0x00, 0xDA, 0xDA, 0xDA },
+    { 0x00, 0xDB, 0xDB, 0xDB },
+    { 0x00, 0xDC, 0xDC, 0xDC },
+    { 0x00, 0xDD, 0xDD, 0xDD },
+    { 0x00, 0xDE, 0xDE, 0xDE },
+    { 0x00, 0xDF, 0xDF, 0xDF },
+    { 0x00, 0xE0, 0xE0, 0xE0 },
+    { 0x00, 0xE1, 0xE1, 0xE1 },
+    { 0x00, 0xE2, 0xE2, 0xE2 },
+    { 0x00, 0xE3, 0xE3, 0xE3 },
+    { 0x00, 0xE4, 0xE4, 0xE4 },
+    { 0x00, 0xE5, 0xE5, 0xE5 },
+    { 0x00, 0xE6, 0xE6, 0xE6 },
+    { 0x00, 0xE7, 0xE7, 0xE7 },
+    { 0x00, 0xE8, 0xE8, 0xE8 },
+    { 0x00, 0xE9, 0xE9, 0xE9 },
+    { 0x00, 0xEA, 0xEA, 0xEA },
+    { 0x00, 0xEB, 0xEB, 0xEB },
+    { 0x00, 0xEC, 0xEC, 0xEC },
+    { 0x00, 0xED, 0xED, 0xED },
+    { 0x00, 0xEE, 0xEE, 0xEE },
+    { 0x00, 0xEF, 0xEF, 0xEF },
+    { 0x00, 0xF0, 0xF0, 0xF0 },
+    { 0x00, 0xF1, 0xF1, 0xF1 },
+    { 0x00, 0xF2, 0xF2, 0xF2 },
+    { 0x00, 0xF3, 0xF3, 0xF3 },
+    { 0x00, 0xF4, 0xF4, 0xF4 },
+    { 0x00, 0xF5, 0xF5, 0xF5 },
+    { 0x00, 0xF6, 0xF6, 0xF6 },
+    { 0x00, 0xF7, 0xF7, 0xF7 },
+    { 0x00, 0xF8, 0xF8, 0xF8 },
+    { 0x00, 0xF9, 0xF9, 0xF9 },
+    { 0x00, 0xFA, 0xFA, 0xFA },
+    { 0x00, 0xFB, 0xFB, 0xFB },
+    { 0x00, 0xFC, 0xFC, 0xFC },
+    { 0x00, 0xFD, 0xFD, 0xFD },
+    { 0x00, 0xFE, 0xFE, 0xFE },
+    { 0x00, 0xFF, 0xFF, 0xFF }
+};
+
+struct lconv _PDCLIB_lconv = { 
+    /* _PDCLIB_ctype      */ _ctype + 1,
+    /* _PDCLIB_errno_texts */
+    {
+        /* no error */ (char *)"",
+        /* ERANGE   */ (char *)"ERANGE (Range error)",
+        /* EDOM     */ (char *)"EDOM (Domain error)",
+        /* EILSEQ   */ (char *)"EILSEQ (Illegal sequence)"
+    },
+    /* decimal_point      */ (char *)".",
+    /* thousands_sep      */ (char *)"",
+    /* grouping           */ (char *)"",
+    /* mon_decimal_point  */ (char *)"",
+    /* mon_thousands_sep  */ (char *)"",
+    /* mon_grouping       */ (char *)"",
+    /* positive_sign      */ (char *)"",
+    /* negative_sign      */ (char *)"",
+    /* currency_symbol    */ (char *)"",
+    /* int_curr_symbol    */ (char *)"",
+    /* frac_digits        */ CHAR_MAX,
+    /* p_cs_precedes      */ CHAR_MAX,
+    /* n_cs_precedes      */ CHAR_MAX,
+    /* p_sep_by_space     */ CHAR_MAX,
+    /* n_sep_by_space     */ CHAR_MAX,
+    /* p_sign_posn        */ CHAR_MAX,
+    /* n_sign_posn        */ CHAR_MAX,
+    /* int_frac_digits    */ CHAR_MAX,
+    /* int_p_cs_precedes  */ CHAR_MAX,
+    /* int_n_cs_precedes  */ CHAR_MAX,
+    /* int_p_sep_by_space */ CHAR_MAX,
+    /* int_n_sep_by_space */ CHAR_MAX,
+    /* int_p_sign_posn    */ CHAR_MAX,
+    /* int_n_sign_posn    */ CHAR_MAX,
+};
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+    /* Testing covered by several other testdrivers using stdin / stdout / 
+       stderr.
+    */
+    return TEST_RESULTS;
+}
+
+#endif
diff --git a/platform/posix/functions/_PDCLIB/stdinit.o b/platform/posix/functions/_PDCLIB/stdinit.o
new file mode 100644 (file)
index 0000000..158283c
Binary files /dev/null and b/platform/posix/functions/_PDCLIB/stdinit.o differ
diff --git a/platform/posix/functions/signal/raise.o b/platform/posix/functions/signal/raise.o
new file mode 100644 (file)
index 0000000..a652efb
Binary files /dev/null and b/platform/posix/functions/signal/raise.o differ
similarity index 93%
rename from platform/example_cygwin/functions/signal/signal.c
rename to platform/posix/functions/signal/signal.c
index 33722aceb65e5d14d38fd411af9f2b5c80a01d7f..e07877d248f49e579d491121d220c8860bd0ded7 100644 (file)
@@ -22,6 +22,10 @@ void (*_PDCLIB_sigterm)( int ) = SIG_DFL;
 void (*signal( int sig, void (*func)( int ) ) )( int )
 {
     void (*oldhandler)( int );
+    if ( sig <= 0 || func == SIG_ERR )
+    {
+        return SIG_ERR;
+    }
     switch ( sig )
     {
         case SIGABRT:
@@ -65,7 +69,7 @@ void (*signal( int sig, void (*func)( int ) ) )( int )
 
 int main( void )
 {
-    TESTCASE( NO_TESTDRIVER );
+    /* Testing covered by raise.c */
     return TEST_RESULTS;
 }
 #endif
diff --git a/platform/posix/functions/signal/signal.o b/platform/posix/functions/signal/signal.o
new file mode 100644 (file)
index 0000000..c4455e4
Binary files /dev/null and b/platform/posix/functions/signal/signal.o differ
similarity index 79%
rename from platform/example_cygwin/functions/stdio/remove.c
rename to platform/posix/functions/stdio/remove.c
index e27dd56efe2cfcfc83167a9cfb87753ea5797c13..389df301be224d6945d6b8a250f7e31a82ca7543 100644 (file)
 
 #ifndef REGTEST
 
+#include <string.h>
+
 #include "/usr/include/errno.h"
 
+extern struct _PDCLIB_file_t * _PDCLIB_filelist;
+
 extern int unlink( const char * pathname );
 
 int remove( const char * pathname )
 {
     int rc;
+    struct _PDCLIB_file_t * current = _PDCLIB_filelist;
+    while ( current != NULL )
+    {
+        if ( ( current->filename != NULL ) && ( strcmp( current->filename, pathname ) == 0 ) )
+        {
+            return EOF;
+        }
+        current = current->next;
+    }
     if ( ( rc = unlink( pathname ) ) == -1 )
     {
         switch ( errno )
diff --git a/platform/posix/functions/stdio/tmpfile.c b/platform/posix/functions/stdio/tmpfile.c
new file mode 100644 (file)
index 0000000..29750d4
--- /dev/null
@@ -0,0 +1,115 @@
+/* $Id$ */
+
+/* tmpfile( void )
+
+   This file is part of the Public Domain C Library (PDCLib).
+   Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <stdio.h>
+
+#ifndef REGTEST
+
+#include <inttypes.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <_PDCLIB_glue.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+extern struct _PDCLIB_file_t * _PDCLIB_filelist;
+
+/* This is an example implementation of tmpfile() fit for use with POSIX
+   kernels.
+*/
+struct _PDCLIB_file_t * tmpfile( void )
+{
+    FILE * rc;
+    /* This is the chosen way to get high-quality randomness. Replace as
+       appropriate.
+    */
+    FILE * randomsource = fopen( "/proc/sys/kernel/random/uuid", "rb" );
+    char filename[ L_tmpnam ];
+    _PDCLIB_fd_t fd;
+    if ( randomsource == NULL )
+    {
+        return NULL;
+    }
+    for ( ;; )
+    {
+        /* Get a filename candidate. What constitutes a valid filename and
+           where temporary files are usually located is platform-dependent,
+           which is one reason why this function is located in the platform
+           overlay. The other reason is that a *good* implementation should
+           use high-quality randomness instead of a pseudo-random sequence to
+           generate the filename candidate, which is *also* platform-dependent.
+        */
+        unsigned int random;
+        fscanf( randomsource, "%u", &random ); 
+        sprintf( filename, "/tmp/%u.tmp", random );
+        /* Check if file of this name exists. Note that fopen() is a very weak
+           check, which does not take e.g. access permissions into account
+           (file might exist but not readable). Replace with something more
+           appropriate.
+        */
+        fd = open( filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR );
+        if ( fd != -1 )
+        {
+            break;
+        }
+        close( fd );
+    }
+    fclose( randomsource );
+    /* See fopen(). */
+    if ( ( rc = calloc( 1, sizeof( struct _PDCLIB_file_t ) + _PDCLIB_UNGETCBUFSIZE + L_tmpnam + BUFSIZ ) ) == NULL )
+    {
+        /* No memory to set up FILE structure */
+        close( fd );
+        return NULL;
+    }
+    rc->status = _PDCLIB_filemode( "wb+" ) | _IOLBF | _PDCLIB_DELONCLOSE;
+    rc->handle = fd;
+    rc->ungetbuf = (unsigned char *)rc + sizeof( struct _PDCLIB_file_t );
+    rc->filename = (char *)rc->ungetbuf + _PDCLIB_UNGETCBUFSIZE;
+    rc->buffer   = rc->filename + L_tmpnam;
+    strcpy( rc->filename, filename );
+    rc->bufsize = BUFSIZ;
+    rc->bufidx = 0;
+    rc->ungetidx = 0;
+    rc->next = _PDCLIB_filelist;
+    _PDCLIB_filelist = rc;
+    return rc;
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+#include <string.h>
+
+int main( void )
+{
+    FILE * fh;
+#ifndef REGTEST
+    char filename[ L_tmpnam ];
+    FILE * fhtest;
+#endif
+    TESTCASE( ( fh = tmpfile() ) != NULL );
+    TESTCASE( fputc( 'x', fh ) == 'x' );
+    /* Checking that file is actually there */
+    TESTCASE_NOREG( strcpy( filename, fh->filename ) == filename );
+    TESTCASE_NOREG( ( fhtest = fopen( filename, "r" ) ) != NULL );
+    TESTCASE_NOREG( fclose( fhtest ) == 0 );
+    /* Closing tmpfile */
+    TESTCASE( fclose( fh ) == 0 );
+    /* Checking that file was deleted */
+    TESTCASE_NOREG( fopen( filename, "r" ) == NULL );
+    return TEST_RESULTS;
+}
+
+#endif
+
diff --git a/platform/posix/functions/stdlib/getenv.o b/platform/posix/functions/stdlib/getenv.o
new file mode 100644 (file)
index 0000000..7117ea7
Binary files /dev/null and b/platform/posix/functions/stdlib/getenv.o differ
similarity index 72%
rename from platform/example_cygwin/functions/stdlib/system.c
rename to platform/posix/functions/stdlib/system.c
index 2e0079a449d942178badaedf8d98a285e842d95d..eb8db3dbd9022f6b80f39881289ed95e3c820d1f 100644 (file)
@@ -40,7 +40,17 @@ int system( const char * string )
 
 int main( void )
 {
+    FILE * fh;
+    char buffer[25];
+    buffer[24] = 'x';
+    TESTCASE( ( fh = freopen( testfile, "wb+", stdout ) ) != NULL );
     TESTCASE( system( SHELLCOMMAND ) );
+    rewind( fh );
+    TESTCASE( fread( buffer, 1, 24, fh ) == 24 );
+    TESTCASE( memcmp( buffer, "SUCCESS testing system()", 24 ) == 0 );
+    TESTCASE( buffer[24] == 'x' );
+    TESTCASE( fclose( fh ) == 0 );
+    TESTCASE( remove( testfile ) == 0 );
     return TEST_RESULTS;
 }
 
diff --git a/platform/posix/functions/stdlib/system.o b/platform/posix/functions/stdlib/system.o
new file mode 100644 (file)
index 0000000..3804cb6
Binary files /dev/null and b/platform/posix/functions/stdlib/system.o differ
similarity index 97%
rename from platform/example_cygwin/includes/float.h
rename to platform/posix/includes/float.h
index de47aeb501358af370570ff668326a47dc672e62..659053997fc9b7b62a590db93c96a2bcfbea4cb8 100644 (file)
@@ -8,11 +8,7 @@
 
 #ifndef _PDCLIB_FLOAT_H
 #define _PDCLIB_FLOAT_H _PDCLIB_FLOAT_H
-
-#ifndef _PDCLIB_CONFIG_H
-#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H
 #include <_PDCLIB_config.h>
-#endif
 
 #define FLT_ROUNDS      _PDCLIB_FLT_ROUNDS
 #define FLT_EVAL_METHOD _PDCLIB_FLT_EVAL_METHOD
similarity index 97%
rename from platform/example_cygwin/includes/signal.h
rename to platform/posix/includes/signal.h
index 9b812c96d66f4dba17fc27b489b9686b4c971446..9f6a1a3abc4252850902d4a94bb158e66361ae02 100644 (file)
@@ -8,11 +8,7 @@
 
 #ifndef _PDCLIB_SIGNAL_H
 #define _PDCLIB_SIGNAL_H _PDCLIB_SIGNAL_H
-
-#ifndef _PDCLIB_CONFIG_H
-#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H
 #include <_PDCLIB_config.h>
-#endif
 
 /* Signals ------------------------------------------------------------------ */
 
similarity index 68%
rename from platform/example_cygwin/internals/_PDCLIB_config.h
rename to platform/posix/internals/_PDCLIB_config.h
index 2fd09e9706becf513c23796fe4748d5c071eb4f8..7e66178b96ea124ba029b3651e03dfc8739e976c 100644 (file)
@@ -1,4 +1,5 @@
-/* $Id$ */
+#ifndef _PDCLIB_CONFIG_H
+#define _PDCLIB_CONFIG_H
 
 /* Internal PDCLib configuration <_PDCLIB_config.h>
    (Generic Template)
 /* to nothing. (This is to avoid warnings with the exit functions under GCC.) */
 #define _PDCLIB_NORETURN __attribute__(( noreturn ))
 
+/* The maximum value that errno can be set to. This is used to set the size   */
+/* of the array in struct lconv (<locale.h>) holding error messages for the   */
+/* strerror() and perror() functions. (If you change this value because you   */
+/* are using additional errno values, you *HAVE* to provide appropriate error */
+/* messages for *ALL* locales.)                                               */
+/* Default is 4 (0, ERANGE, EDOM, EILSEQ).                                    */
+#define _PDCLIB_ERRNO_MAX 4
+
 /* -------------------------------------------------------------------------- */
 /* Integers                                                                   */
 /* -------------------------------------------------------------------------- */
@@ -162,6 +171,36 @@ struct _PDCLIB_imaxdiv_t
     _PDCLIB_intmax rem;
 };
 
+/* <time.h>: time_t 
+ * The C standard doesn't define what representation of time is stored in 
+ * time_t when returned by time() , but POSIX defines it to be seconds since the
+ * UNIX epoch and most appplications expect that. 
+ *
+ * time_t is also used as the tv_sec member of struct timespec, which *is* 
+ * defined as a linear count of seconds.
+ *
+ * time_t is defined as a "real type", so may be a floating point type, but with
+ * the presence of the nanosecond accurate struct timespec, and with the lack of
+ * any functions for manipulating more accurate values of time_t, this is 
+ * probably not useful.
+ */
+#define _PDCLIB_time  unsigned long long
+
+/* <time.h>: clock_t
+ *
+ * A count of "clock ticks", where the length of a clock tick is unspecified by
+ * the standard. The implementation is required to provide a macro, 
+ * CLOCKS_PER_SEC, which is the number of "clock ticks" which corresponds to one
+ * second.
+ *
+ * clock_t may be any real type (i.e. integral or floating), and its type on
+ * various systems differs. 
+ *
+ * On XSI systems, CLOCKS_PER_SEC must be defined to 1000000
+ */
+#define _PDCLIB_clock double
+#define _PDCLIB_CLOCKS_PER_SEC 1000000
+
 /* -------------------------------------------------------------------------- */
 /* Floating Point                                                             */
 /* -------------------------------------------------------------------------- */
@@ -286,4 +325,121 @@ typedef int _PDCLIB_fd_t;
 */
 #define _PDCLIB_UNGETCBUFSIZE 1
 
-typedef long wint_t;
+/* errno -------------------------------------------------------------------- */
+
+/* These are the values that _PDCLIB_errno can be set to by the library.
+
+   By keeping PDCLib's errno in the _PDCLIB_* namespace, the library is capable
+   to "translate" between errno values used by the hosting operating system and
+   those used and passed out by the library.
+
+   Example: In the example platform, the remove() function uses the unlink()
+   system call as backend. Linux sets its errno to EISDIR if you try to unlink()
+   a directory, but POSIX demands EPERM. Within the remove() function, you can
+   catch the 'errno == EISDIR', and set '_PDCLIB_errno = _PDCLIB_EPERM'. Anyone
+   using PDCLib's <errno.h> will "see" EPERM instead of EISDIR (the _PDCLIB_*
+   prefix removed by <errno.h> mechanics).
+
+   If you do not want that kind of translation, you might want to "match" the
+   values used by PDCLib with those used by the host OS, as to avoid confusion.
+
+   The C standard only defines three distinct errno values: ERANGE, EDOM, and
+   EILSEQ. The standard leaves it up to "the implementation" whether there are
+   any more beyond those three. There is some controversy as to whether errno is
+   such a good idea at all, so you might want to come up with a different error
+   reporting facility for your platform. 
+
+   Things used to say "Since errno values beyond the three defined by the 
+   standard are not portable anyway (unless you look at POSIX), having your own
+   error reporting facility would not hurt anybody either." at this point. 
+   However, then somebody birthed C++11 into the world, which copied POSIX's 
+   errno values into C++. Yes, even EINTR. Therefore, this library defines 
+   them. That said, thats nothing stopping you from using your own error 
+   reporting facility for things outside the C library.
+
+   Sometimes the standard says to set errno to indicate an error, but does not 
+   prescribe a value. We will use a value from the following list. If POSIX 
+   defines a value, we use that; otherwise, we use as seems suitable.
+
+   If porting to a system which uses an errno-like reporting system (e.g. a 
+   UNIX), you'll probably want to define them to match what the OS uses
+*/
+/* C errno values */
+#define _PDCLIB_ERANGE 1
+#define _PDCLIB_EDOM   2
+#define _PDCLIB_EILSEQ 3
+
+/* C++11/POSIX errno values */
+#define _PDCLIB_E2BIG 4
+#define _PDCLIB_ECONNRESET 5
+#define _PDCLIB_EISCONN 6
+#define _PDCLIB_ENOENT 7
+#define _PDCLIB_ENOTRECOVERABLE 8
+#define _PDCLIB_EROFS 9
+#define _PDCLIB_EACCES 10
+#define _PDCLIB_EDEADLK 11
+#define _PDCLIB_EISDIR 12
+#define _PDCLIB_ENOEXEC 13
+#define _PDCLIB_ENOTSOCK 14
+#define _PDCLIB_ESPIPE 15
+#define _PDCLIB_EADDRINUSE 16
+#define _PDCLIB_EDESTADDRREQ 17
+#define _PDCLIB_ELOOP 18
+#define _PDCLIB_ENOLCK 19
+#define _PDCLIB_ENOTSUPP 20
+#define _PDCLIB_ESRCH 21
+#define _PDCLIB_EADDRNOTAVAIL 22
+#define _PDCLIB_EMFILE 23
+#define _PDCLIB_ENOLINK 24
+#define _PDCLIB_ENOTTY 25
+#define _PDCLIB_ETIME 26
+#define _PDCLIB_EAFNOSUPPORT 27
+#define _PDCLIB_EEXIST 28
+#define _PDCLIB_EMLINK 29
+#define _PDCLIB_ENOMEM 30
+#define _PDCLIB_ENXIO 31
+#define _PDCLIB_ETIMEDOUT 32
+#define _PDCLIB_EAGAIN 33
+#define _PDCLIB_EFAULT 34
+#define _PDCLIB_EMSGSIZE 35
+#define _PDCLIB_ENOMSG 36
+#define _PDCLIB_EOPNOTSUPP 37
+#define _PDCLIB_ETXTBSY 38
+#define _PDCLIB_EALREADY 39
+#define _PDCLIB_EFBIG 40
+#define _PDCLIB_ENAMETOOLONG 41
+#define _PDCLIB_ENOPROTOOPT 42
+#define _PDCLIB_EOVERFLOW 43
+#define _PDCLIB_EWOULDBLOCK _PDCLIB_EAGAIN
+#define _PDCLIB_EBADF 44
+#define _PDCLIB_EHOSTUNREACH 45
+#define _PDCLIB_ENETDOWN 46
+#define _PDCLIB_ENOSPC 47
+#define _PDCLIB_EOWNERDEAD 48
+#define _PDCLIB_EXDEV 49
+#define _PDCLIB_EBADMSG 50
+#define _PDCLIB_EIDRM 51
+#define _PDCLIB_ENETRESET 52
+#define _PDCLIB_ENOSR 53
+#define _PDCLIB_EPERM 54
+#define _PDCLIB_EBUSY 55
+#define _PDCLIB_ENETUNREACH 56
+#define _PDCLIB_ENOSTR 57
+#define _PDCLIB_EPIPE 58
+#define _PDCLIB_ECANCELED 59
+#define _PDCLIB_EINPROGRESS 60
+#define _PDCLIB_ENFILE 61
+#define _PDCLIB_ENOSYS 62
+#define _PDCLIB_EPROTO 63
+#define _PDCLIB_ECHILD 64
+#define _PDCLIB_EINTR 65
+#define _PDCLIB_ENOBUFS 66
+#define _PDCLIB_ENOTCONN 67
+#define _PDCLIB_EPROTONOSUPPORT 68
+#define _PDCLIB_ECONNABORTED 69
+#define _PDCLIB_EINVAL 70
+#define _PDCLIB_ENODATA 71
+#define _PDCLIB_ENOTDIR 72
+#define _PDCLIB_EPROTOTYPE 73
+
+#endif