From ed4d5abcad8b07c4a06d2483497066c2c621a6d7 Mon Sep 17 00:00:00 2001 From: solar Date: Thu, 29 Jun 2006 06:32:59 +0000 Subject: [PATCH] Closer to functional printf(). --- functions/stdio/vfprintf.c | 19 ++++++++++++++++++- includes/stdio.h | 8 ++++---- platform/example/functions/_PDCLIB/stdinit.c | 12 ++++++------ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/functions/stdio/vfprintf.c b/functions/stdio/vfprintf.c index 8e3ff95..0288f6d 100644 --- a/functions/stdio/vfprintf.c +++ b/functions/stdio/vfprintf.c @@ -39,9 +39,26 @@ int vfprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDC #ifdef TEST #include <_PDCLIB_test.h> +static int testprintf( FILE * stream, const char * format, ... ) +{ + int i; + va_list arg; + va_start( arg, format ); + i = vfprintf( stream, format, arg ); + va_end( arg ); + return i; +} + int main( void ) { - TESTCASE( NO_TESTDRIVER ); + FILE * fh; + TESTCASE( testprintf( stdout, "Hallo\n" ) == 6 ); +#if 0 + TESTCASE( ( fh = fopen( "testfile", "w" ) ) != NULL ); + TESTCASE( testprintf( fh, "Hallo\n" ) ); + TESTCASE( fclose( fh ) == 0 ); + TESTCASE( remove( "testfile" ) == 0 ); +#endif return TEST_RESULTS; } diff --git a/includes/stdio.h b/includes/stdio.h index 06f0f44..c1ebcb1 100644 --- a/includes/stdio.h +++ b/includes/stdio.h @@ -31,7 +31,7 @@ typedef _PDCLIB_size_t size_t; /* The following are platform-dependant, and defined in _PDCLIB_config.h. */ typedef _PDCLIB_fpos_t fpos_t; -//typedef struct _PDCLIB_file_t FILE; +typedef struct _PDCLIB_file_t FILE; #define EOF -1 #define BUFSIZ _PDCLIB_BUFSIZ #define FOPEN_MAX _PDCLIB_FOPEN_MAX @@ -44,9 +44,9 @@ typedef _PDCLIB_fpos_t fpos_t; #define SEEK_END 2 #define SEEK_SET 4 -//extern FILE * stdin; -//extern FILE * stdout; -//extern FILE * stderr; +extern struct _PDCLIB_file_t * stdin; +extern struct _PDCLIB_file_t * stdout; +extern struct _PDCLIB_file_t * stderr; /* Operations on files */ diff --git a/platform/example/functions/_PDCLIB/stdinit.c b/platform/example/functions/_PDCLIB/stdinit.c index f83bc4f..baf6985 100644 --- a/platform/example/functions/_PDCLIB/stdinit.c +++ b/platform/example/functions/_PDCLIB/stdinit.c @@ -18,17 +18,17 @@ /* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file descriptors 0, 1, and 2 respectively. */ -#if 0 -/* FIXME: Disabled for initial stdio.h development. */ /* TODO: This is proof-of-concept, requires finetuning. */ -static struct _PDCLIB_file_t _PDCLIB_sin = { 0, { 0, 0 }, 0, 0, 0, /* mbstate, */ 0 }; -static struct _PDCLIB_file_t _PDCLIB_sout = { 1, { 0, 0 }, 0, 0, 0, /* mbstate, */ 0 }; -static struct _PDCLIB_file_t _PDCLIB_serr = { 2, { 0, 0 }, 0, 0, 0, /* mbstate, */ 0 }; +static char _PDCLIB_sin_buffer[BUFSIZ]; +static char _PDCLIB_sout_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 }; struct _PDCLIB_file_t * stdin = &_PDCLIB_sin; struct _PDCLIB_file_t * stdout = &_PDCLIB_sout; struct _PDCLIB_file_t * stderr = &_PDCLIB_serr; -#endif #endif -- 2.40.0