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_io.h>
12 extern char * _PDCLIB_eol;
14 int _PDCLIB_puts_unlocked( 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 );
43 int puts( const char * s )
45 _PDCLIB_flockfile( stdout );
46 int r = _PDCLIB_puts_unlocked( s );
47 _PDCLIB_funlockfile( stdout );
54 #include <_PDCLIB_test.h>
59 char const * message = "SUCCESS testing puts()";
62 TESTCASE( ( fh = freopen( testfile, "wb+", stdout ) ) != NULL );
63 TESTCASE( puts( message ) >= 0 );
65 TESTCASE( fread( buffer, 1, 22, fh ) == 22 );
66 TESTCASE( memcmp( buffer, message, 22 ) == 0 );
67 TESTCASE( buffer[22] == 'x' );
68 TESTCASE( fclose( fh ) == 0 );
69 TESTCASE( remove( testfile ) == 0 );