]> pd.if.org Git - pdclib/commitdiff
Closer to functional printf().
authorsolar <unknown>
Thu, 29 Jun 2006 06:32:59 +0000 (06:32 +0000)
committersolar <unknown>
Thu, 29 Jun 2006 06:32:59 +0000 (06:32 +0000)
functions/stdio/vfprintf.c
includes/stdio.h
platform/example/functions/_PDCLIB/stdinit.c

index 8e3ff9548482a81610cd12f937c191e310c76aff..0288f6d74b90b9c17fa38ee43a6a68acc01e634a 100644 (file)
@@ -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;
 }
 
index 06f0f4435ea5bfd650413f5c94161368bdd386d8..c1ebcb1a43591b68bf69d63097884688a706eb5c 100644 (file)
@@ -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 */
 
index f83bc4fd236ea7c566e6442b0117449c4516987c..baf6985f4eaad7ee1568babed56693f8870ffdc9 100644 (file)
 /* 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