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_io.h"
12 int _PDCLIB_fputs_unlocked( const char * _PDCLIB_restrict s,
13 FILE * _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 )
47 int fputs( const char * _PDCLIB_restrict s,
48 FILE * _PDCLIB_restrict stream )
50 _PDCLIB_flockfile( stream );
51 int r = _PDCLIB_fputs_unlocked( s, stream );
52 _PDCLIB_funlockfile( stream );
58 #include "_PDCLIB_test.h"
62 char const * const message = "SUCCESS testing fputs()";
64 TESTCASE( ( fh = tmpfile() ) != NULL );
65 TESTCASE( fputs( message, fh ) >= 0 );
67 for ( size_t i = 0; i < 23; ++i )
69 TESTCASE( fgetc( fh ) == message[i] );
71 TESTCASE( fclose( fh ) == 0 );