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 /* TODO: Should IOLBF flush on \n, or the correct EOL sequence of the system? */
28 if ( ( stream->bufidx == stream->bufsize )
29 || ( ( 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 testfile = "testfile";
55 char const * const message = "SUCCESS testing fputs()";
58 TESTCASE( ( fh = fopen( testfile, "w+" ) ) != NULL );
59 TESTCASE( fputs( message, fh ) >= 0 );
61 for ( size_t i = 0; i < 23; ++i )
63 TESTCASE( fgetc( fh ) == message[i] );
65 TESTCASE( fclose( fh ) == 0 );
66 TESTCASE( remove( testfile ) == 0 );