X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstdio%2Fputs.c;fp=functions%2Fstdio%2Fputs.c;h=a90e07863fbdb26185b9ae2827da22eed895b054;hp=40c9727643fa3ad424cd33032b59e75f9950e2f3;hb=393020b6e48719d27699dea6b29e53025bbd5123;hpb=f408c1fd633015089d2a0fc6bc31c9f61eeae0a9 diff --git a/functions/stdio/puts.c b/functions/stdio/puts.c index 40c9727..a90e078 100644 --- a/functions/stdio/puts.c +++ b/functions/stdio/puts.c @@ -9,10 +9,43 @@ #include #ifndef REGTEST +#include <_PDCLIB_glue.h> + +extern char * _PDCLIB_eol; int puts( const char * s ) { - /* TODO: Implement. */ + if ( _PDCLIB_prepwrite( stdout ) == EOF ) + { + return EOF; + } + while ( *s != '\0' ) + { + stdout->buffer[ stdout->bufidx++ ] = *s++; + if ( stdout->bufidx == stdout->bufsize ) + { + if ( _PDCLIB_flushbuffer( stdout ) == EOF ) + { + return EOF; + } + } + } + s = _PDCLIB_eol; + while ( *s != '\0' ) + { + stdout->buffer[ stdout->bufidx++ ] = *s++; + if ( stdout->bufidx == stdout->bufsize ) + { + if ( _PDCLIB_flushbuffer( stdout ) == EOF ) + { + return EOF; + } + } + } + if ( stdout->status & ( _IOLBF | _IONBF ) ) + { + return _PDCLIB_flushbuffer( stdout ); + } return 0; } @@ -23,8 +56,9 @@ int puts( const char * s ) int main( void ) { - TESTCASE( NO_TESTDRIVER ); + TESTCASE( puts( "SUCCESS testing puts()" ) >= 0 ); return TEST_RESULTS; } #endif +