]> pd.if.org Git - pdclib/blobdiff - functions/stdio/setbuf.c
Added some functions.
[pdclib] / functions / stdio / setbuf.c
index d9b722b88f46ba37f82fd342bd2a9eefa85eef2f..e77d2d4807692e80373c08080d95e78bc1f1c041 100644 (file)
@@ -1,7 +1,5 @@
 /* $Id$ */
 
-/* Release $Name$ */
-
 /* setbuf( FILE *, char * )
 
    This file is part of the Public Domain C Library (PDCLib).
@@ -12,7 +10,7 @@
 
 #ifndef REGTEST
 
-void setbuf( FILE * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf )
+void setbuf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf )
 {
     /* TODO: Only allowed on a "virgin" stream; add check. */
     if ( buf == NULL )
@@ -32,7 +30,34 @@ void setbuf( FILE * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf )
 
 int main( void )
 {
-    TESTCASE( NO_TESTDRIVER );
+    /* TODO: Extend testing once setvbuf() is finished. */
+#ifndef REGTEST
+    char const * const filename = "testfile";
+    char buffer[ 100 ];
+    struct _PDCLIB_file_t * fh;
+    /* full buffered */
+    TESTCASE( ( fh = fopen( filename, "w" ) ) != NULL );
+    TESTCASE( fh->status & _PDCLIB_LIBBUFFER );
+    TESTCASE( fh->bufsize == BUFSIZ );
+    setbuf( fh, buffer );
+#if 0
+    TESTCASE( fh->buffer == buffer );
+    TESTCASE( fh->bufsize == BUFFERSIZE );
+#endif
+    TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOFBF );
+    TESTCASE( fclose( fh ) == 0 );
+    /* not buffered */
+    TESTCASE( ( fh = fopen( filename, "w" ) ) != NULL );
+    setbuf( fh, NULL );
+#if 0
+    TESTCASE( fh->buffer == NULL );
+    TESTCASE( fh->bufsize == 0 );
+#endif
+    TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IONBF );
+    TESTCASE( fclose( fh ) == 0 );
+#else
+    puts( " NOTEST setbuf() test driver is PDCLib-specific." );
+#endif
     return TEST_RESULTS;
 }