1 /* fputs( const char *, FILE * )
3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
11 #include "_PDCLIB_glue.h"
13 int fputs( const char * _PDCLIB_restrict s, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
15 if ( _PDCLIB_prepwrite( stream ) == EOF )
21 /* Unbuffered and line buffered streams get flushed when fputs() does
22 write the terminating end-of-line. All streams get flushed if the
25 stream->buffer[ stream->bufidx++ ] = *s;
26 if ( ( stream->bufidx == stream->bufsize ) ||
27 ( ( stream->status & _IOLBF ) && *s == '\n' )
30 if ( _PDCLIB_flushbuffer( stream ) == EOF )
37 if ( stream->status & _IONBF )
39 if ( _PDCLIB_flushbuffer( stream ) == EOF )
51 #include "_PDCLIB_test.h"
55 char const * const message = "SUCCESS testing fputs()";
57 TESTCASE( ( fh = tmpfile() ) != 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 );