#ifndef REGTEST
#include <_PDCLIB_glue.h>
+extern int PDCLIB_NO_ACTUAL_STDIO();
+
int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream )
{
- stream->buffer[0] = inbyte();
- stream->pos.offset += 1;
- stream->bufend = 1;
- stream->bufidx = 0;
- return 0;
+ return PDCLIB_NO_ACTUAL_STDIO();
}
#endif
int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream )
{
- char *c = stream->buffer;
- int i = stream->bufidx;
- while (i--)
- outbyte(*c++);
- return 0;
+ return PDCLIB_NO_ACTUAL_STDIO();
}
#endif
--- /dev/null
+/* $Id$ */
+
+/* _PDCLIB_prepread( struct _PDCLIB_file_t * )
+
+ 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>
+
+extern int PDCLIB_NO_ACTUAL_STDIO();
+
+int _PDCLIB_prepread( struct _PDCLIB_file_t * stream )
+{
+ return PDCLIB_NO_ACTUAL_STDIO();
+}
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ /* Testing covered by ftell.c */
+ return TEST_RESULTS;
+}
+
+#endif
+
--- /dev/null
+/* $Id$ */
+
+/* _PDCLIB_prepwrite( struct _PDCLIB_file_t * )
+
+ 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>
+
+extern int PDCLIB_NO_ACTUAL_STDIO();
+
+int _PDCLIB_prepwrite( struct _PDCLIB_file_t * stream )
+{
+ return PDCLIB_NO_ACTUAL_STDIO();
+}
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ /* Testing covered by ftell.c */
+ return TEST_RESULTS;
+}
+
+#endif
+
--- /dev/null
+/* $Id$ */
+
+/* fflush( 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>
+
+#ifndef REGTEST
+
+int fflush( struct _PDCLIB_file_t * stream )
+{
+ flush();
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ /* Testing covered by ftell.c */
+ return TEST_RESULTS;
+}
+
+#endif
+
--- /dev/null
+/* $Id$ */
+
+/* fgetc( 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>
+
+#ifndef REGTEST
+
+int fgetc( struct _PDCLIB_file_t * stream )
+{
+ return getchar();
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ /* Testing covered by ftell.c */
+ return TEST_RESULTS;
+}
+
+#endif
--- /dev/null
+/* $Id$ */
+
+/* fgetpos( FILE * , fpos_t * )
+
+ 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>
+
+#ifndef REGTEST
+
+int fgetpos( struct _PDCLIB_file_t * _PDCLIB_restrict stream, struct _PDCLIB_fpos_t * _PDCLIB_restrict pos )
+{
+ pos->offset = 0;
+ pos->status = 0;
+ /* TODO: Add mbstate. */
+ return 0;
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+#include <string.h>
+
+int main( void )
+{
+ FILE * fh;
+ fpos_t pos1, pos2;
+ TESTCASE( ( fh = tmpfile() ) != NULL );
+ TESTCASE( fgetpos( fh, &pos1 ) == 0 );
+ TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) );
+ TESTCASE( fgetpos( fh, &pos2 ) == 0 );
+ TESTCASE( fsetpos( fh, &pos1 ) == 0 );
+ TESTCASE( ftell( fh ) == 0 );
+ TESTCASE( fsetpos( fh, &pos2 ) == 0 );
+ TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) );
+ TESTCASE( fclose( fh ) == 0 );
+ return TEST_RESULTS;
+}
+
+#endif
--- /dev/null
+/* $Id$ */
+
+/* fgets( char *, int, 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>
+
+#ifndef REGTEST
+
+char * fgets( char * _PDCLIB_restrict s, int size, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+{
+ if ( size == 0 )
+ {
+ return NULL;
+ }
+ if ( size == 1 )
+ {
+ *s = '\0';
+ return s;
+ }
+ char * dest = s;
+ for (;;) {
+ int c = getc(stream);
+ if (c == EOF)
+ break;
+ *dest++ = c;
+ if (c == '\n')
+ break;
+ if (--size <= 0)
+ break;
+ }
+ *dest = '\0';
+ return ( dest == s ) ? NULL : s;
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+#include <string.h>
+
+int main( void )
+{
+ FILE * fh;
+ char buffer[10];
+ char const * fgets_test = "foo\nbar\0baz\nweenie";
+ TESTCASE( ( fh = fopen( testfile, "wb+" ) ) != NULL );
+ TESTCASE( fwrite( fgets_test, 1, 18, fh ) == 18 );
+ rewind( fh );
+ TESTCASE( fgets( buffer, 10, fh ) == buffer );
+ TESTCASE( strcmp( buffer, "foo\n" ) == 0 );
+ TESTCASE( fgets( buffer, 10, fh ) == buffer );
+ TESTCASE( memcmp( buffer, "bar\0baz\n", 8 ) == 0 );
+ TESTCASE( fgets( buffer, 10, fh ) == buffer );
+ TESTCASE( strcmp( buffer, "weenie" ) == 0 );
+ TESTCASE( feof( fh ) );
+ TESTCASE( fseek( fh, -1, SEEK_END ) == 0 );
+ TESTCASE( fgets( buffer, 1, fh ) == buffer );
+ TESTCASE( strcmp( buffer, "" ) == 0 );
+ TESTCASE( fgets( buffer, 0, fh ) == NULL );
+ TESTCASE( ! feof( fh ) );
+ TESTCASE( fgets( buffer, 1, fh ) == buffer );
+ TESTCASE( strcmp( buffer, "" ) == 0 );
+ TESTCASE( ! feof( fh ) );
+ TESTCASE( fgets( buffer, 2, fh ) == buffer );
+ TESTCASE( strcmp( buffer, "e" ) == 0 );
+ TESTCASE( fseek( fh, 0, SEEK_END ) == 0 );
+ TESTCASE( fgets( buffer, 2, fh ) == NULL );
+ TESTCASE( feof( fh ) );
+ TESTCASE( fclose( fh ) == 0 );
+ TESTCASE( remove( testfile ) == 0 );
+ return TEST_RESULTS;
+}
+
+#endif
+
--- /dev/null
+/* $Id$ */
+
+/* fputc( int, 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>
+
+#ifndef REGTEST
+
+extern void ao_putchar(char c);
+
+/* Write the value c (cast to unsigned char) to the given stream.
+ Returns c if successful, EOF otherwise.
+ If a write error occurs, the error indicator of the stream is set.
+*/
+int fputc( int c, struct _PDCLIB_file_t * stream )
+{
+ ao_putchar(c);
+ return c;
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ /* Testing covered by ftell.c */
+ return TEST_RESULTS;
+}
+
+#endif
--- /dev/null
+/* $Id$ */
+
+/* fputs( const char *, 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>
+
+#ifndef REGTEST
+#include <_PDCLIB_glue.h>
+
+int fputs( const char * _PDCLIB_restrict s, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+{
+ char c;
+
+ while ((c = *s++))
+ if (putc(stream, c) != c)
+ return EOF;
+ return 0;
+}
+
+#endif
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ char const * const message = "SUCCESS testing fputs()";
+ FILE * fh;
+ TESTCASE( ( fh = tmpfile() ) != NULL );
+ TESTCASE( fputs( message, fh ) >= 0 );
+ rewind( fh );
+ for ( size_t i = 0; i < 23; ++i )
+ {
+ TESTCASE( fgetc( fh ) == message[i] );
+ }
+ TESTCASE( fclose( fh ) == 0 );
+ return TEST_RESULTS;
+}
+
+#endif
+
--- /dev/null
+/* $Id$ */
+
+/* fwrite( 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>
+
+#ifndef REGTEST
+
+#include <_PDCLIB_glue.h>
+
+#include <stdbool.h>
+#include <string.h>
+
+size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+{
+ char * dest = (char *)ptr;
+ size_t nmemb_i;
+ for ( nmemb_i = 0; nmemb_i < nmemb; ++nmemb_i )
+ {
+ for ( size_t size_i = 0; size_i < size; ++size_i )
+ {
+ int c = getc(stream);
+ if (c == EOF)
+ {
+ /* Could not read requested data */
+ return nmemb_i;
+ }
+ *dest++ = c;
+ }
+ }
+ return nmemb_i;
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ FILE * fh;
+ char const * message = "Testing fwrite()...\n";
+ char buffer[21];
+ buffer[20] = 'x';
+ TESTCASE( ( fh = tmpfile() ) != NULL );
+ /* fwrite() / readback */
+ TESTCASE( fwrite( message, 1, 20, fh ) == 20 );
+ rewind( fh );
+ TESTCASE( fread( buffer, 1, 20, fh ) == 20 );
+ TESTCASE( memcmp( buffer, message, 20 ) == 0 );
+ TESTCASE( buffer[20] == 'x' );
+ /* same, different nmemb / size settings */
+ rewind( fh );
+ TESTCASE( memset( buffer, '\0', 20 ) == buffer );
+ TESTCASE( fwrite( message, 5, 4, fh ) == 4 );
+ rewind( fh );
+ TESTCASE( fread( buffer, 5, 4, fh ) == 4 );
+ TESTCASE( memcmp( buffer, message, 20 ) == 0 );
+ TESTCASE( buffer[20] == 'x' );
+ /* same... */
+ rewind( fh );
+ TESTCASE( memset( buffer, '\0', 20 ) == buffer );
+ TESTCASE( fwrite( message, 20, 1, fh ) == 1 );
+ rewind( fh );
+ TESTCASE( fread( buffer, 20, 1, fh ) == 1 );
+ TESTCASE( memcmp( buffer, message, 20 ) == 0 );
+ TESTCASE( buffer[20] == 'x' );
+ /* Done. */
+ TESTCASE( fclose( fh ) == 0 );
+ return TEST_RESULTS;
+}
+
+#endif
+
--- /dev/null
+/* $Id$ */
+
+/* fsetpos( FILE *, const fpos_t * )
+
+ 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>
+
+#ifndef REGTEST
+
+int fsetpos( struct _PDCLIB_file_t * stream, const struct _PDCLIB_fpos_t * pos )
+{
+ stream->pos.status = 0;
+ /* TODO: Add mbstate. */
+ return 0;
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ /* fsetpos() tested together with fsetpos(). */
+ 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>
+
+#ifndef REGTEST
+
+#include <_PDCLIB_glue.h>
+
+#include <stdbool.h>
+#include <string.h>
+
+size_t fwrite( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+{
+ size_t total = size * nmemb;
+ size_t written = 0;
+ char *data = ptr;
+
+ while (total-- > 0)
+ {
+ char c = *data++;
+ if (putc(c, stream) != c)
+ break;
+ written++;
+ }
+ return written / size;
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ /* Testing covered by fread(). */
+ return TEST_RESULTS;
+}
+
+#endif
+
--- /dev/null
+/* $Id$ */
+
+/* gets( char * )
+
+ 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>
+
+#ifndef REGTEST
+
+char * gets( char * s )
+{
+ char *dest = s;
+ int c;
+
+ for (;;) {
+ c = getchar();
+ if (c == '\n' || c == EOF)
+ break;
+ *dest++ = c;
+ }
+ *dest = '\0';
+ return ( dest == s ) ? NULL : s;
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+#include <string.h>
+
+int main( void )
+{
+ FILE * fh;
+ char buffer[10];
+ char const * gets_test = "foo\nbar\0baz\nweenie";
+ TESTCASE( ( fh = fopen( testfile, "wb" ) ) != NULL );
+ TESTCASE( fwrite( gets_test, 1, 18, fh ) == 18 );
+ TESTCASE( fclose( fh ) == 0 );
+ TESTCASE( ( fh = freopen( testfile, "rb", stdin ) ) != NULL );
+ TESTCASE( gets( buffer ) == buffer );
+ TESTCASE( strcmp( buffer, "foo" ) == 0 );
+ TESTCASE( gets( buffer ) == buffer );
+ TESTCASE( memcmp( buffer, "bar\0baz\0", 8 ) == 0 );
+ TESTCASE( gets( buffer ) == buffer );
+ TESTCASE( strcmp( buffer, "weenie" ) == 0 );
+ TESTCASE( feof( fh ) );
+ TESTCASE( fseek( fh, -1, SEEK_END ) == 0 );
+ TESTCASE( gets( buffer ) == buffer );
+ TESTCASE( strcmp( buffer, "e" ) == 0 );
+ TESTCASE( feof( fh ) );
+ TESTCASE( fseek( fh, 0, SEEK_END ) == 0 );
+ TESTCASE( gets( buffer ) == NULL );
+ TESTCASE( fclose( fh ) == 0 );
+ TESTCASE( remove( testfile ) == 0 );
+ return TEST_RESULTS;
+}
+
+#endif
+
--- /dev/null
+/* $Id$ */
+
+/* puts( const char * )
+
+ 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>
+
+#ifndef REGTEST
+
+int puts( const char * s )
+{
+ char c;
+
+ while ((c = *s++))
+ if (putchar (c) != c)
+ return EOF;
+ if (putchar('\n') != '\n')
+ return EOF;
+ return 0;
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ FILE * fh;
+ char const * message = "SUCCESS testing puts()";
+ char buffer[23];
+ buffer[22] = 'x';
+ TESTCASE( ( fh = freopen( testfile, "wb+", stdout ) ) != NULL );
+ TESTCASE( puts( message ) >= 0 );
+ rewind( fh );
+ TESTCASE( fread( buffer, 1, 22, fh ) == 22 );
+ TESTCASE( memcmp( buffer, message, 22 ) == 0 );
+ TESTCASE( buffer[22] == 'x' );
+ TESTCASE( fclose( fh ) == 0 );
+ TESTCASE( remove( testfile ) == 0 );
+ return TEST_RESULTS;
+}
+
+#endif
+
--- /dev/null
+/* $Id$ */
+
+/* ungetc( int, 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>
+
+#ifndef REGTEST
+
+extern int PDCLIB_NO_ACTUAL_STDIO();
+
+int ungetc( int c, struct _PDCLIB_file_t * stream )
+{
+ return PDCLIB_NO_ACTUAL_STDIO();
+}
+
+#endif
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+ /* Testing covered by ftell.c */
+ return TEST_RESULTS;
+}
+
+#endif