X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Fsetbuf.c;h=46db8e3374c109a92494b705e042635db67347a7;hb=015e9131c3aa3f39b34612d0d2fce242f6deb7b4;hp=e77d2d4807692e80373c08080d95e78bc1f1c041;hpb=725b1cc72b121ef663aaf23bdaa1a512ae45adb6;p=pdclib.old diff --git a/functions/stdio/setbuf.c b/functions/stdio/setbuf.c index e77d2d4..46db8e3 100644 --- a/functions/stdio/setbuf.c +++ b/functions/stdio/setbuf.c @@ -12,7 +12,6 @@ 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 ) { setvbuf( stream, buf, _IONBF, BUFSIZ ); @@ -27,34 +26,29 @@ void setbuf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, char * _PDCLIB_res #ifdef TEST #include <_PDCLIB_test.h> +#include int main( void ) { /* TODO: Extend testing once setvbuf() is finished. */ #ifndef REGTEST - char const * const filename = "testfile"; - char buffer[ 100 ]; - struct _PDCLIB_file_t * fh; + char buffer[ BUFSIZ + 1 ]; + FILE * fh; + remove( testfile ); /* full buffered */ - TESTCASE( ( fh = fopen( filename, "w" ) ) != NULL ); - TESTCASE( fh->status & _PDCLIB_LIBBUFFER ); - TESTCASE( fh->bufsize == BUFSIZ ); + TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL ); setbuf( fh, buffer ); -#if 0 TESTCASE( fh->buffer == buffer ); - TESTCASE( fh->bufsize == BUFFERSIZE ); -#endif + TESTCASE( fh->bufsize == BUFSIZ ); TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOFBF ); TESTCASE( fclose( fh ) == 0 ); + TESTCASE( remove( testfile ) == 0 ); /* not buffered */ - TESTCASE( ( fh = fopen( filename, "w" ) ) != NULL ); + TESTCASE( ( fh = fopen( testfile, "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 ); + TESTCASE( remove( testfile ) == 0 ); #else puts( " NOTEST setbuf() test driver is PDCLib-specific." ); #endif