]> pd.if.org Git - pdclib/blob - functions/stdio/setbuf.c
Added testdriver.
[pdclib] / functions / stdio / setbuf.c
1 /* $Id$ */
2
3 /* setbuf( FILE *, char * )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <stdio.h>
10
11 #ifndef REGTEST
12
13 void setbuf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf )
14 {
15     /* TODO: Only allowed on a "virgin" stream; add check. */
16     if ( buf == NULL )
17     {
18         setvbuf( stream, buf, _IONBF, BUFSIZ );
19     }
20     else
21     {
22         setvbuf( stream, buf, _IOFBF, BUFSIZ );
23     }
24 }
25
26 #endif
27
28 #ifdef TEST
29 #include <_PDCLIB_test.h>
30
31 int main( void )
32 {
33     /* TODO: Extend testing once setvbuf() is finished. */
34 #ifndef REGTEST
35     char const * const filename = "testfile";
36     char buffer[ 100 ];
37     struct _PDCLIB_file_t * fh;
38     /* full buffered */
39     TESTCASE( ( fh = fopen( filename, "w" ) ) != NULL );
40     TESTCASE( fh->status & _PDCLIB_LIBBUFFER );
41     TESTCASE( fh->bufsize == BUFSIZ );
42     setbuf( fh, buffer );
43 #if 0
44     TESTCASE( fh->buffer == buffer );
45     TESTCASE( fh->bufsize == BUFFERSIZE );
46 #endif
47     TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOFBF );
48     TESTCASE( fclose( fh ) == 0 );
49     /* not buffered */
50     TESTCASE( ( fh = fopen( filename, "w" ) ) != NULL );
51     setbuf( fh, NULL );
52 #if 0
53     TESTCASE( fh->buffer == NULL );
54     TESTCASE( fh->bufsize == 0 );
55 #endif
56     TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IONBF );
57     TESTCASE( fclose( fh ) == 0 );
58 #else
59     puts( " NOTEST setbuf() test driver is PDCLib-specific." );
60 #endif
61     return TEST_RESULTS;
62 }
63
64 #endif