]> pd.if.org Git - pdclib.old/blob - functions/stdio/fgetc.c
Namespace cleanliness: Rename all ***_unlocked functions to _PDCLIB_***_unlocked.
[pdclib.old] / functions / stdio / fgetc.c
1 /* $Id$ */
2
3 /* fgetc( FILE * )
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_io.h>
13
14 int _PDCLIB_fgetc_unlocked( FILE * stream )
15 {
16     if ( _PDCLIB_prepread( stream ) == EOF )
17     {
18         return EOF;
19     }
20
21     char c;
22
23     size_t n = _PDCLIB_getchars( &c, 1, EOF, stream );
24
25     return n == 0 ? EOF : (unsigned char) c;
26 }
27
28 int fgetc( FILE * stream )
29 {
30     _PDCLIB_flockfile( stream );
31     int c = _PDCLIB_fgetc_unlocked( stream );
32     _PDCLIB_funlockfile( stream );
33     return c;
34 }
35
36 #endif
37
38 #ifdef TEST
39 #include <_PDCLIB_test.h>
40
41 int main( void )
42 {
43     /* Testing covered by ftell.c */
44     return TEST_RESULTS;
45 }
46
47 #endif