#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;
}
/* 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
#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 */
/* 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