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