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_unlocked( 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 );
45 int puts( const char * s )
48 int r = puts_unlocked( s );
49 funlockfile( stdout );
56 #include <_PDCLIB_test.h>
61 char const * message = "SUCCESS testing puts()";
64 TESTCASE( ( fh = freopen( testfile, "wb+", stdout ) ) != NULL );
65 TESTCASE( puts( message ) >= 0 );
67 TESTCASE( fread( buffer, 1, 22, fh ) == 22 );
68 TESTCASE( memcmp( buffer, message, 22 ) == 0 );
69 TESTCASE( buffer[22] == 'x' );
70 TESTCASE( fclose( fh ) == 0 );
71 TESTCASE( remove( testfile ) == 0 );