3 /* puts( const char * )
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 extern char * _PDCLIB_eol;
16 int puts( const char * s )
18 if ( _PDCLIB_prepwrite( stdout ) == EOF )
24 stdout->buffer[ stdout->bufidx++ ] = *s++;
25 if ( stdout->bufidx == stdout->bufsize )
27 if ( _PDCLIB_flushbuffer( stdout ) == EOF )
33 stdout->buffer[ stdout->bufidx++ ] = '\n';
34 if ( ( stdout->bufidx == stdout->bufsize ) ||
35 ( stdout->status & ( _IOLBF | _IONBF ) ) )
37 return _PDCLIB_flushbuffer( stdout );
48 #include <_PDCLIB_test.h>
53 char const * message = "SUCCESS testing puts()";
56 TESTCASE( ( fh = freopen( testfile, "wb+", stdout ) ) != NULL );
57 TESTCASE( puts( message ) >= 0 );
59 TESTCASE( fread( buffer, 1, 22, fh ) == 22 );
60 TESTCASE( memcmp( buffer, message, 22 ) == 0 );
61 TESTCASE( buffer[22] == 'x' );
62 TESTCASE( fclose( fh ) == 0 );
63 TESTCASE( remove( testfile ) == 0 );