3 /* fputs( const char *, FILE * )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
12 #include <_PDCLIB_glue.h>
14 int fputs( const char * _PDCLIB_restrict s, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
16 if ( _PDCLIB_prepwrite( stream ) == EOF )
22 /* Unbuffered and line buffered streams get flushed when fputs() does
23 write the terminating end-of-line. All streams get flushed if the
26 stream->buffer[ stream->bufidx++ ] = *s;
27 if ( ( stream->bufidx == stream->bufsize ) ||
28 ( ( stream->status & _IOLBF ) && *s == '\n' )
31 if ( _PDCLIB_flushbuffer( stream ) == EOF )
38 if ( stream->status & _IONBF )
40 if ( _PDCLIB_flushbuffer( stream ) == EOF )
50 #include <_PDCLIB_test.h>
54 char const * const message = "SUCCESS testing fputs()";
57 TESTCASE( ( fh = fopen( testfile, "w+" ) ) != NULL );
58 TESTCASE( fputs( message, fh ) >= 0 );
60 for ( size_t i = 0; i < 23; ++i )
62 TESTCASE( fgetc( fh ) == message[i] );
64 TESTCASE( fclose( fh ) == 0 );
65 TESTCASE( remove( testfile ) == 0 );