int main( void )
{
+#ifndef REGTEST
+ FILE file = { 0, { 0 }, NULL, 0, 0, 0, NULL };
+ FILE * fh = &file;
+ TESTCASE( ! ferror( fh ) );
+ TESTCASE( ! feof( fh ) );
+ fh->status |= _PDCLIB_ERRORFLAG;
+ TESTCASE( ferror( fh ) );
+ TESTCASE( ! feof( fh ) );
+ clearerr( fh );
+ TESTCASE( ! ferror( fh ) );
+ TESTCASE( ! feof( fh ) );
+ fh->status |= _PDCLIB_EOFFLAG;
+ TESTCASE( ! ferror( fh ) );
+ TESTCASE( feof( fh ) );
+ clearerr( fh );
+ TESTCASE( ! ferror( fh ) );
+ TESTCASE( ! feof( fh ) );
+ fh->status |= _PDCLIB_EOFFLAG | _PDCLIB_ERRORFLAG;
+ TESTCASE( ferror( fh ) );
+ TESTCASE( feof( fh ) );
+ clearerr( fh );
+ TESTCASE( ! ferror( fh ) );
+ TESTCASE( ! feof( fh ) );
+#else
+ /* TODO: The above is ad-hoc and PDCLib specific. A better test driver
+ should be internals-agnostic (provoking the error / eof flag by
+ "regular" operations).
+ */
TESTCASE( NO_TESTDRIVER );
+#endif
return TEST_RESULTS;
}
int main( void )
{
- TESTCASE( NO_TESTDRIVER );
+ /* Testing covered by clearerr(). */
return TEST_RESULTS;
}
int main( void )
{
- TESTCASE( NO_TESTDRIVER );
+ /* Testing covered by clearerr(). */
return TEST_RESULTS;
}
*/
stream->buffer[stream->bufidx++] = (char)c;
if ( ( stream->bufidx == stream->bufsize ) /* _IOFBF */
- || ( ( stream->status & _IOLBF ) && (char)c == '\n' ) /* _IOLBF */
+ || ( ( stream->status & _IOLBF ) && ( (char)c == '\n' ) ) /* _IOLBF */
|| ( stream->status & _IONBF ) /* _IONBF */
)
{
/* buffer filled, unbuffered stream, or end-of-line. */
fflush( stream );
}
+ else
+ {
+ stream->status |= _PDCLIB_WROTELAST;
+ }
return c;
}
int main( void )
{
- TESTCASE( NO_TESTDRIVER );
+ FILE * fh;
+ char buffer[100];
+ TESTCASE( ( fh = fopen( "testfile", "w" ) ) != NULL );
+ TESTCASE( fputc( '!', fh ) == '!' );
+ TESTCASE( fclose( fh ) == 0 );
+ TESTCASE( ( fh = fopen( "testfile", "r" ) ) != NULL );
+ TESTCASE( fread( buffer, 1, 1, fh ) == 1 );
+ TESTCASE( buffer[0] == '!' );
+ TESTCASE( fclose( fh ) == 0 );
return TEST_RESULTS;
}
#ifdef TEST
#include <_PDCLIB_test.h>
+#include <string.h>
+
int main( void )
{
- TESTCASE( NO_TESTDRIVER );
+ FILE * fh;
+ char buffer[100];
+ char text[] = "SUCCESS testing fputs().";
+ TESTCASE( ( fh = fopen( "testfile", "w" ) ) != NULL );
+ TESTCASE( fputs( text, fh ) != EOF );
+ TESTCASE( fclose( fh ) == 0 );
+ TESTCASE( ( fh = fopen( "testfile", "r" ) ) != NULL );
+ TESTCASE( fread( buffer, 1, strlen( text ), fh ) == strlen( text ) );
+ TESTCASE( memcmp( buffer, text, strlen( text ) ) == 0 );
+ TESTCASE( fclose( fh ) == 0 );
+ TESTCASE( remove( "testfile" ) == 0 );
return TEST_RESULTS;
}
--- /dev/null
+/* $Id$ */
+
+/* fread( void *, size_t, size_t, FILE * )
+
+ 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>
+#include <_PDCLIB_glue.h>
+
+#ifndef REGTEST
+
+size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+{
+ return _PDCLIB_read( stream->handle, ptr, size * nmemb );
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ /* Testing handled by fwrite(). */
+ return TEST_RESULTS;
+}
+
+#endif
--- /dev/null
+/* $Id$ */
+
+/* fwrite( const void *, size_t, size_t, FILE * )
+
+ 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>
+#include <_PDCLIB_glue.h>
+
+#ifndef REGTEST
+
+size_t fwrite( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+{
+ return _PDCLIB_write( stream->handle, ptr, size * nmemb );
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ FILE * fh;
+ TESTCASE( ( fh = fopen( "testfile", "w" ) ) != NULL );
+ TESTCASE( fwrite( "SUCCESS testing fwrite()\n", 1, 25, fh ) == 25 );
+ TESTCASE( fclose( fh ) == 0 );
+ /* TODO: Add readback test. */
+ TESTCASE( remove( "testfile" ) == 0 );
+ return TEST_RESULTS;
+}
+
+#endif
int main( void )
{
- TESTCASE( NO_TESTDRIVER );
+ TESTCASE( printf( "SUCCESS testing printf().\n" ) == 26 );
return TEST_RESULTS;
}
{
/* No conversion specifier, print verbatim */
putc( *(format++), stream );
+ status.i++;
}
else
{
#endif
#ifdef TEST
+#include <stdlib.h>
#include <_PDCLIB_test.h>
static int testprintf( FILE * stream, const char * format, ... )
int main( void )
{
FILE * fh;
- TESTCASE( testprintf( stdout, "Hallo\n" ) == 6 );
-#if 0
TESTCASE( ( fh = fopen( "testfile", "w" ) ) != NULL );
- TESTCASE( testprintf( fh, "Hallo\n" ) );
+ TESTCASE( testprintf( fh, "Hallo\n" ) == 6 );
TESTCASE( fclose( fh ) == 0 );
- TESTCASE( remove( "testfile" ) == 0 );
-#endif
+ /* FIXME: Testfile doesn't exist... */
return TEST_RESULTS;
}
*/
#include <stdlib.h>
+#include <stdio.h>
#include <_PDCLIB_glue.h>
#ifndef REGTEST
void _Exit( int status )
{
- /* TODO: Flush and close open streams. Remove tmpfile() files. */
+ /* TODO: Flush and close open streams. Remove tmpfile() files. Make this
+ called on process termination automatically.
+ */
_PDCLIB_Exit( status );
}
if ( _PDCLIB_memlist.last == NULL )
{
_PDCLIB_memlist.first = splitnode;
- splitnode->next = NULL;
}
else
{
_PDCLIB_memlist.last->next = splitnode;
}
+ splitnode->next = NULL; /* TODO: This is bug #7, uncovered by testdriver yet. */
_PDCLIB_memlist.last = splitnode;
}
return (char *)newnode + sizeof( struct _PDCLIB_memnode_t );
--- /dev/null
+/* $Id$ */
+
+/* _PDCLIB_read( _PDCLIB_fd_t, char *, _PDCLIB_size_t )
+
+ This file is part of the Public Domain C Library (PDCLib).
+ Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <_PDCLIB_glue.h>
+
+#ifndef REGTEST
+
+int read(int, void *, unsigned int);
+
+_PDCLIB_size_t _PDCLIB_read( _PDCLIB_fd_t fd, char * buffer, _PDCLIB_size_t n )
+{
+ return read( fd, buffer, n );
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ TESTCASE( NO_TESTDRIVER );
+ return TEST_RESULTS;
+}
+
+#endif
/* 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 struct _PDCLIB_file_t _PDCLIB_serr = { 2, { 0 }, NULL, 0, 0, 0u, /* mbstate, */ NULL };
-static struct _PDCLIB_file_t _PDCLIB_sout = { 1, { 0 }, _PDCLIB_sout_buffer, BUFSIZ, 0, 0u, /* mbstate, */ &_PDCLIB_serr };
-static struct _PDCLIB_file_t _PDCLIB_sin = { 0, { 0 }, _PDCLIB_sin_buffer, BUFSIZ, 0, 0u, /* mbstate, */ &_PDCLIB_sout };
+/* FIXME: serr should handle one character. Buffering on out / in? */
+static struct _PDCLIB_file_t _PDCLIB_serr = { 2, { 0 }, _PDCLIB_serr_buffer, BUFSIZ, 0, _IONBF, /* mbstate, */ NULL };
+static struct _PDCLIB_file_t _PDCLIB_sout = { 1, { 0 }, _PDCLIB_sout_buffer, BUFSIZ, 0, _IOLBF, /* mbstate, */ &_PDCLIB_serr };
+static struct _PDCLIB_file_t _PDCLIB_sin = { 0, { 0 }, _PDCLIB_sin_buffer, BUFSIZ, 0, _IOLBF, /* mbstate, */ &_PDCLIB_sout };
struct _PDCLIB_file_t * stdin = &_PDCLIB_sin;
struct _PDCLIB_file_t * stdout = &_PDCLIB_sout;
--- /dev/null
+/* $Id$ */
+
+/* _PDCLIB_write( _PDCLIB_fd_t, char const *, _PDCLIB_size_t )
+
+ This file is part of the Public Domain C Library (PDCLib).
+ Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <_PDCLIB_glue.h>
+
+#ifndef REGTEST
+
+int write(int, const void *, unsigned int);
+
+_PDCLIB_size_t _PDCLIB_write( _PDCLIB_fd_t fd, char const * buffer, _PDCLIB_size_t n )
+{
+ return write( fd, buffer, n );
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ TESTCASE( NO_TESTDRIVER );
+ return TEST_RESULTS;
+}
+
+#endif