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.
10 #include <_PDCLIB_glue.h>
12 int fputs( const char * _PDCLIB_restrict s, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
14 if ( _PDCLIB_prepwrite( stream ) == EOF )
20 /* Unbuffered and line buffered streams get flushed when fputs() does
21 write the terminating end-of-line. All streams get flushed if the
24 stream->buffer[ stream->bufidx++ ] = *s;
25 if ( ( stream->bufidx == stream->bufsize ) ||
26 ( ( stream->status & _IOLBF ) && *s == '\n' )
29 if ( _PDCLIB_flushbuffer( stream ) == EOF )
36 if ( stream->status & _IONBF )
38 if ( _PDCLIB_flushbuffer( stream ) == EOF )
48 #include <_PDCLIB_test.h>
52 char const * const message = "SUCCESS testing fputs()";
54 TESTCASE( ( fh = tmpfile() ) != NULL );
55 TESTCASE( fputs( message, fh ) >= 0 );
57 for ( size_t i = 0; i < 23; ++i )
59 TESTCASE( fgetc( fh ) == message[i] );
61 TESTCASE( fclose( fh ) == 0 );