1 /* puts( const char * )
3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
11 #include "_PDCLIB_glue.h"
13 extern char * _PDCLIB_eol;
15 int puts( const char * s )
17 if ( _PDCLIB_prepwrite( stdout ) == EOF )
23 stdout->buffer[ stdout->bufidx++ ] = *s++;
24 if ( stdout->bufidx == stdout->bufsize )
26 if ( _PDCLIB_flushbuffer( stdout ) == EOF )
32 stdout->buffer[ stdout->bufidx++ ] = '\n';
33 if ( ( stdout->bufidx == stdout->bufsize ) ||
34 ( stdout->status & ( _IOLBF | _IONBF ) ) )
36 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 );