From 9b1e6c0a721f9358d9bbc76410e719a878e27edb Mon Sep 17 00:00:00 2001 From: solar Date: Wed, 7 Jun 2006 14:16:45 +0000 Subject: [PATCH] Added close(). --- internals/_PDCLIB_glue.h | 6 ++-- platform/example/functions/_PDCLIB/close.c | 39 ++++++++++++++++++++++ platform/example/functions/_PDCLIB/open.c | 12 +++---- 3 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 platform/example/functions/_PDCLIB/close.c diff --git a/internals/_PDCLIB_glue.h b/internals/_PDCLIB_glue.h index 0ffbebc..f390dfa 100644 --- a/internals/_PDCLIB_glue.h +++ b/internals/_PDCLIB_glue.h @@ -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 index 0000000..fd85f4c --- /dev/null +++ b/platform/example/functions/_PDCLIB/close.c @@ -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 + +#ifndef REGTEST +#include <_PDCLIB_glue.h> + +#include +#include +#include +#include + +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 diff --git a/platform/example/functions/_PDCLIB/open.c b/platform/example/functions/_PDCLIB/open.c index 98354f9..5feec6e 100644 --- a/platform/example/functions/_PDCLIB/open.c +++ b/platform/example/functions/_PDCLIB/open.c @@ -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; -- 2.40.0