e28a2b8c0595fb064ecd099a6034ef8168834d08
[fw/pdclib] / functions / stdio / puts.c
1 /* $Id$ */
2
3 /* puts( const char * )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <stdio.h>
10
11 #ifndef REGTEST
12 #include <_PDCLIB_glue.h>
13
14 extern char * _PDCLIB_eol;
15
16 int puts( const char * s )
17 {
18     if ( _PDCLIB_prepwrite( stdout ) == EOF )
19     {
20         return EOF;
21     }
22     while ( *s != '\0' )
23     {
24         stdout->buffer[ stdout->bufidx++ ] = *s++;
25         if ( stdout->bufidx == stdout->bufsize )
26         {
27             if ( _PDCLIB_flushbuffer( stdout ) == EOF )
28             {
29                 return EOF;
30             }
31         }
32     }
33     /* FIXME: Think-o. '\n' is lineend, conversion to platform-specific
34        tales place only for text streams.
35     */
36     s = _PDCLIB_eol;
37     while ( *s != '\0' )
38     {
39         stdout->buffer[ stdout->bufidx++ ] = *s++;
40         if ( stdout->bufidx == stdout->bufsize )
41         {
42             if ( _PDCLIB_flushbuffer( stdout ) == EOF )
43             {
44                 return EOF;
45             }
46         }
47     }
48     if ( stdout->status & ( _IOLBF | _IONBF ) )
49     {
50         return _PDCLIB_flushbuffer( stdout );
51     }
52     return 0;
53 }
54
55 #endif
56
57 #ifdef TEST
58 #include <_PDCLIB_test.h>
59
60 int main( void )
61 {
62     TESTCASE( puts( "SUCCESS testing puts()" ) >= 0 );
63     return TEST_RESULTS;
64 }
65
66 #endif
67