Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/functions/stdio/setbuf.c
2 views
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( FILE * _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
#include "_PDCLIB_test.h"
27
#include <stdlib.h>
28
#ifndef REGTEST
29
#include "_PDCLIB_io.h"
30
#endif
31
32
int main( void )
33
{
34
/* TODO: Extend testing once setvbuf() is finished. */
35
#ifndef REGTEST
36
char buffer[ BUFSIZ + 1 ];
37
FILE * fh;
38
/* full buffered */
39
TESTCASE( ( fh = tmpfile() ) != NULL );
40
setbuf( fh, buffer );
41
TESTCASE( fh->buffer == buffer );
42
TESTCASE( fh->bufsize == BUFSIZ );
43
TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOFBF );
44
TESTCASE( fclose( fh ) == 0 );
45
/* not buffered */
46
TESTCASE( ( fh = tmpfile() ) != NULL );
47
setbuf( fh, NULL );
48
TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IONBF );
49
TESTCASE( fclose( fh ) == 0 );
50
#else
51
puts( " NOTEST setbuf() test driver is PDCLib-specific." );
52
#endif
53
return TEST_RESULTS;
54
}
55
56
#endif
57
58