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 _PDCLIB_open( char const * const filename, unsigned int mode )
{
/* This is an example implementation of _PDCLIB_open() fit for use with
POSIX kernels.
- return open( filename, osmode );
+ rc = open( filename, osmode );
+ }
+ if ( rc == -1 )
+ {
+ switch ( errno )
+ {
+ 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_EIO;
+ default:
+ _PDCLIB_errno = _PDCLIB_EUNKNOWN;
+ }
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( 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( write( fh, "test", 4 ) == -1 );
TESTCASE( _PDCLIB_close( fh ) == 0 );
/* Appending to file, trying to read from it. */
TESTCASE( write( fh, "test", 4 ) == -1 );
TESTCASE( _PDCLIB_close( fh ) == 0 );
/* Appending to file, trying to read from it. */
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( 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( read( fh, buffer, 10 ) == 10 );
TESTCASE( memcmp( buffer, "testappend", 10 ) == 0 );
TESTCASE( lseek( fh, 0, SEEK_SET ) == 0 );
TESTCASE( read( fh, buffer, 10 ) == 10 );
TESTCASE( memcmp( buffer, "testappend", 10 ) == 0 );
TESTCASE( lseek( fh, 0, SEEK_SET ) == 0 );
TESTCASE( memcmp( buffer, "wedoappend", 10 ) == 0 );
TESTCASE( _PDCLIB_close( fh ) == 0 );
/* Writing and reading from file ("w+"). */
TESTCASE( memcmp( buffer, "wedoappend", 10 ) == 0 );
TESTCASE( _PDCLIB_close( fh ) == 0 );
/* Writing and reading from file ("w+"). */
TESTCASE( write( fh, "test", 4 ) == 4 );
TESTCASE( lseek( fh, 1, SEEK_SET ) == 1 );
TESTCASE( read( fh, buffer, 2 ) == 2 );
TESTCASE( write( fh, "test", 4 ) == 4 );
TESTCASE( lseek( fh, 1, SEEK_SET ) == 1 );
TESTCASE( read( fh, buffer, 2 ) == 2 );
TESTCASE( memcmp( buffer, "tessie", 6 ) == 0 );
TESTCASE( _PDCLIB_close( fh ) == 0 );
/* Appending and reading from file ("a+"). */
TESTCASE( memcmp( buffer, "tessie", 6 ) == 0 );
TESTCASE( _PDCLIB_close( fh ) == 0 );
/* Appending and reading from file ("a+"). */
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( 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. */