]> pd.if.org Git - pdclib/blobdiff - platform/example/functions/_PDCLIB/open.c
Intermediate work, checked in for safekeeping as I pick up working on this again.
[pdclib] / platform / example / functions / _PDCLIB / open.c
index 98354f9b4af4ef51431437fe9d1fb853f5873fff..fc82485aec2d730b3505ee6e3e655e1c83faa11b 100644 (file)
 #include <fcntl.h>
 #include <unistd.h>
 
-_PDCLIB_fd_t _PDCLIB_open( char const * const filename, unsigned int mode )
+int _PDCLIB_open( char const * const filename, unsigned int mode )
 {
-    /* FIXME: THIS IS NOT TO BE USED OUT-OF-THE-BOX.
-       It is a proof-of-concept implementation. E.g. a stream may only be fully
-       buffered IF IT CAN BE DETERMINED NOT TO REFER TO AN INTERACTIVE DEVICE.
-       This logic is not represented here, as this is the EXAMPLE platform, and
-       actual platform overlays may differ widely. Another point is the value
-       for permissions being hardcoded to 0664 for file creations.
+    /* 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_FBIN )
@@ -78,7 +76,7 @@ int main( void )
     /* This testdriver assumes POSIX, i.e. _PDCLIB_fd_t being int and being
        incremented by one on each successful open.
     */
-    _PDCLIB_fd_t fh;
+    int fh;
     char buffer[ 10 ];
     /* Trying to read non-existent file. */
     TESTCASE( _PDCLIB_open( "testfile", _PDCLIB_FREAD ) == _PDCLIB_NOHANDLE );
@@ -87,18 +85,18 @@ int main( void )
     TESTCASE( write( fh, "test", 4 ) == 4 );
     TESTCASE( lseek( fh, 0, SEEK_SET ) == 0 );
     TESTCASE( read( fh, buffer, 4 ) == -1 );
-    TESTCASE( close( fh ) == 0 );
+    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( close( fh ) == 0 );
+    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( close( fh ) == 0 );
+    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 );
@@ -108,7 +106,7 @@ int main( void )
     TESTCASE( lseek( fh, 0, SEEK_SET ) == 0 );
     TESTCASE( read( fh, buffer, 10 ) == 10 );
     TESTCASE( memcmp( buffer, "wedoappend", 10 ) == 0 );
-    TESTCASE( close( fh ) == 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 );
@@ -119,17 +117,18 @@ int main( void )
     TESTCASE( lseek( fh, 0, SEEK_SET ) == 0 );
     TESTCASE( read( fh, buffer, 6 ) == 6 );
     TESTCASE( memcmp( buffer, "tessie", 6 ) == 0 );
-    TESTCASE( close( fh ) == 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( close( fh ) == 0 );
+    TESTCASE( _PDCLIB_close( fh ) == 0 );
     /* Cleaning up. */
     system( "rm testfile" );
     return TEST_RESULTS;
 }
 
 #endif
+