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.
10 #include <_PDCLIB_glue.h>
12 extern char * _PDCLIB_eol;
14 int puts( const char * s )
16 if ( _PDCLIB_prepwrite( stdout ) == EOF )
22 stdout->buffer[ stdout->bufidx++ ] = *s++;
23 if ( stdout->bufidx == stdout->bufsize )
25 if ( _PDCLIB_flushbuffer( stdout ) == EOF )
31 stdout->buffer[ stdout->bufidx++ ] = '\n';
32 if ( ( stdout->bufidx == stdout->bufsize ) ||
33 ( stdout->status & ( _IOLBF | _IONBF ) ) )
35 return _PDCLIB_flushbuffer( stdout );
46 #include <_PDCLIB_test.h>
51 char const * message = "SUCCESS testing puts()";
54 TESTCASE( ( fh = freopen( testfile, "wb+", stdout ) ) != NULL );
55 TESTCASE( puts( message ) >= 0 );
57 TESTCASE( fread( buffer, 1, 22, fh ) == 22 );
58 TESTCASE( memcmp( buffer, message, 22 ) == 0 );
59 TESTCASE( buffer[22] == 'x' );
60 TESTCASE( fclose( fh ) == 0 );
61 TESTCASE( remove( testfile ) == 0 );