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_io.h>
14 int _PDCLIB_fputs_unlocked( const char * _PDCLIB_restrict s,
15 FILE * _PDCLIB_restrict stream )
17 if ( _PDCLIB_prepwrite( stream ) == EOF )
23 /* Unbuffered and line buffered streams get flushed when fputs() does
24 write the terminating end-of-line. All streams get flushed if the
27 stream->buffer[ stream->bufidx++ ] = *s;
28 if ( ( stream->bufidx == stream->bufsize ) ||
29 ( ( stream->status & _IOLBF ) && *s == '\n' )
32 if ( _PDCLIB_flushbuffer( stream ) == EOF )
39 if ( stream->status & _IONBF )
41 if ( _PDCLIB_flushbuffer( stream ) == EOF )
49 int fputs( const char * _PDCLIB_restrict s,
50 FILE * _PDCLIB_restrict stream )
52 _PDCLIB_flockfile( stream );
53 int r = _PDCLIB_fputs_unlocked( s, stream );
54 _PDCLIB_funlockfile( stream );
60 #include <_PDCLIB_test.h>
64 char const * const message = "SUCCESS testing fputs()";
66 TESTCASE( ( fh = tmpfile() ) != NULL );
67 TESTCASE( fputs( message, fh ) >= 0 );
69 for ( size_t i = 0; i < 23; ++i )
71 TESTCASE( fgetc( fh ) == message[i] );
73 TESTCASE( fclose( fh ) == 0 );