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/_PDCLIB_glue.h" 12 13 #ifndef __STDC_NO_THREADS__ 14 #include <threads.h> 15 #endif 16 fputc(int c,struct _PDCLIB_file_t * stream)17int fputc( int c, struct _PDCLIB_file_t * stream ) 18 { 19 _PDCLIB_LOCK( stream->mtx ); 20 21 if ( _PDCLIB_prepwrite( stream ) == EOF ) 22 { 23 _PDCLIB_UNLOCK( stream->mtx ); 24 return EOF; 25 } 26 27 stream->buffer[stream->bufidx++] = ( char )c; 28 29 if ( ( stream->bufidx == stream->bufsize ) /* _IOFBF */ 30 || ( ( stream->status & _IOLBF ) && ( ( char )c == '\n' ) ) /* _IOLBF */ 31 || ( stream->status & _IONBF ) /* _IONBF */ 32 ) 33 { 34 /* buffer filled, unbuffered stream, or end-of-line. */ 35 c = ( _PDCLIB_flushbuffer( stream ) == 0 ) ? c : EOF; 36 } 37 38 _PDCLIB_UNLOCK( stream->mtx ); 39 40 return c; 41 } 42 43 #endif 44 45 #ifdef TEST 46 47 #include "_PDCLIB_test.h" 48 main(void)49int main( void ) 50 { 51 /* Testing covered by ftell.c */ 52 return TEST_RESULTS; 53 } 54 55 #endif 56