]> pd.if.org Git - pdclib/commitdiff
Added close().
authorsolar <unknown>
Wed, 7 Jun 2006 14:16:45 +0000 (14:16 +0000)
committersolar <unknown>
Wed, 7 Jun 2006 14:16:45 +0000 (14:16 +0000)
internals/_PDCLIB_glue.h
platform/example/functions/_PDCLIB/close.c [new file with mode: 0644]
platform/example/functions/_PDCLIB/open.c

index 0ffbebc7eb6b97a1fa0d89e488ff5f6dde826931..f390dfaa84bf773169b516a89596e46133fa603b 100644 (file)
@@ -45,8 +45,10 @@ _PDCLIB_size_t _PDCLIB_write( _PDCLIB_fd_t fd, char const * buffer, _PDCLIB_size
 */
 _PDCLIB_size_t _PDCLIB_read( _PDCLIB_fd_t fd, char * buffer, _PDCLIB_size_t n );
 
-/* A system call that closes a file identified by given file descriptor. */
-void _PDCLIB_close( _PDCLIB_fd_t fd );
+/* A system call that closes a file identified by given file descriptor. Return
+   zero on success, non-zero otherwise.
+*/
+int _PDCLIB_close( _PDCLIB_fd_t fd );
 
 /* A system call that removes a file identified by name. Return zero on success,
    non-zero otherwise.
diff --git a/platform/example/functions/_PDCLIB/close.c b/platform/example/functions/_PDCLIB/close.c
new file mode 100644 (file)
index 0000000..fd85f4c
--- /dev/null
@@ -0,0 +1,39 @@
+/* $Id$ */
+
+/* _PDCLIB_close( _PDCLIB_fd_t fd )
+
+   This file is part of the Public Domain C Library (PDCLib).
+   Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+/* This is an example implementation of _PDCLIB_close() fit for use with POSIX
+   kernels.
+*/
+
+#include <stdio.h>
+
+#ifndef REGTEST
+#include <_PDCLIB_glue.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+int _PDCLIB_close( _PDCLIB_fd_t fd )
+{
+    return close( fd );
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+    /* No testdriver; tested in driver for _PDCLIB_open(). */
+    return TEST_RESULTS;
+}
+
+#endif
index 98354f9b4af4ef51431437fe9d1fb853f5873fff..5feec6e828a89a3c8ccb0e2ff8c14492b2cdf22f 100644 (file)
@@ -87,18 +87,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 +108,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,14 +119,14 @@ 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;