]> pd.if.org Git - pdclib/blob - functions/stdio/fputc.c
Comment cleanups.
[pdclib] / functions / stdio / fputc.c
1 /* fputc( int, FILE * )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <stdio.h>
8
9 #ifndef REGTEST
10
11 #include <_PDCLIB_glue.h>
12
13 /* Write the value c (cast to unsigned char) to the given stream.
14    Returns c if successful, EOF otherwise.
15    If a write error occurs, the error indicator of the stream is set.
16 */
17 int fputc( int c, struct _PDCLIB_file_t * stream )
18 {
19     if ( _PDCLIB_prepwrite( stream ) == EOF )
20     {
21         return EOF;
22     }
23     stream->buffer[stream->bufidx++] = (char)c;
24     if ( ( stream->bufidx == stream->bufsize )                   /* _IOFBF */
25            || ( ( stream->status & _IOLBF ) && ( (char)c == '\n' ) ) /* _IOLBF */
26            || ( stream->status & _IONBF )                        /* _IONBF */
27     )
28     {
29         /* buffer filled, unbuffered stream, or end-of-line. */
30         return ( _PDCLIB_flushbuffer( stream ) == 0 ) ? c : EOF;
31     }
32     return c;
33 }
34
35 #endif
36
37 #ifdef TEST
38 #include <_PDCLIB_test.h>
39
40 int main( void )
41 {
42     /* Testing covered by ftell.c */
43     return TEST_RESULTS;
44 }
45
46 #endif