Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/functions/stdio/fputc.c
2 views
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
#include "_PDCLIB_io.h"
11
12
/* Write the value c (cast to unsigned char) to the given stream.
13
Returns c if successful, EOF otherwise.
14
If a write error occurs, the error indicator of the stream is set.
15
*/
16
int _PDCLIB_fputc_unlocked( int c, FILE * stream )
17
{
18
if ( _PDCLIB_prepwrite( stream ) == EOF )
19
{
20
return EOF;
21
}
22
stream->buffer[stream->bufidx++] = (char)c;
23
if ( ( stream->bufidx == stream->bufsize ) /* _IOFBF */
24
|| ( ( stream->status & _IOLBF ) && ( (char)c == '\n' ) ) /* _IOLBF */
25
|| ( stream->status & _IONBF ) /* _IONBF */
26
)
27
{
28
/* buffer filled, unbuffered stream, or end-of-line. */
29
return ( _PDCLIB_flushbuffer( stream ) == 0 ) ? c : EOF;
30
}
31
return c;
32
}
33
34
int fputc( int c, FILE * stream )
35
{
36
_PDCLIB_flockfile( stream );
37
int r = _PDCLIB_fputc_unlocked( c, stream );
38
_PDCLIB_funlockfile( stream );
39
return r;
40
}
41
42
#endif
43
44
#ifdef TEST
45
#include "_PDCLIB_test.h"
46
47
int main( void )
48
{
49
/* Testing covered by ftell.c */
50
return TEST_RESULTS;
51
}
52
53
#endif
54
55