]> pd.if.org Git - pdclib/blob - functions/stdio/fgetc.c
PDCLIB-18: Unify fgetc under _PDCLIB_getchars. Also unify gets under _PDCLIB_getchars...
[pdclib] / 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
13 #include <_PDCLIB_glue.h>
14
15 int fgetc_unlocked( struct _PDCLIB_file_t * stream )
16 {
17     if ( _PDCLIB_prepread( stream ) == EOF )
18     {
19         return EOF;
20     }
21
22     char c;
23
24     size_t n = _PDCLIB_getchars( &c, 1, EOF, stream );
25
26     return n == 0 ? EOF : (unsigned char) c;
27 }
28
29 int fgetc( struct _PDCLIB_file_t * stream )
30 {
31     flockfile( stream );
32     int c = fgetc_unlocked( stream );
33     funlockfile( stream );
34     return c;
35 }
36
37 #endif
38
39 #ifdef TEST
40 #include <_PDCLIB_test.h>
41
42 int main( void )
43 {
44     /* Testing covered by ftell.c */
45     return TEST_RESULTS;
46 }
47
48 #endif