OSDN Git Service

Last portion of libc_hidden_proto removal.
[uclinux-h8/uClibc.git] / libc / stdio / fgetc.c
1 /* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
2  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
3  *
4  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
5  *
6  * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
7  */
8
9 #include "_stdio.h"
10
11 #undef fgetc
12 #undef fgetc_unlocked
13 #undef getc
14 #undef getc_unlocked
15
16 /* libc_hidden_proto(__fgetc_unlocked) */
17
18 #ifdef __DO_UNLOCKED
19
20 /* libc_hidden_proto(fflush_unlocked) */
21
22 int __fgetc_unlocked(FILE *stream)
23 {
24         __STDIO_STREAM_VALIDATE(stream);
25
26         /* First the fast path.  We're good to go if getc macro enabled. */
27         if (__STDIO_STREAM_CAN_USE_BUFFER_GET(stream)) {
28                 return __STDIO_STREAM_BUFFER_GET(stream);
29         }
30
31         /* Next quickest... reading and narrow oriented, but macro
32          * disabled and/or buffer is exhausted. */
33         if (__STDIO_STREAM_IS_NARROW_READING(stream)
34                 || !__STDIO_STREAM_TRANS_TO_READ(stream, __FLAG_NARROW)
35                 ) {
36                 if (stream->__modeflags & __FLAG_UNGOT) { /* Use ungots first. */
37                         unsigned char uc = stream->__ungot[(stream->__modeflags--) & 1];
38                         stream->__ungot[1] = 0;
39                         __STDIO_STREAM_VALIDATE(stream);
40                         return uc;
41                 }
42
43                 if (__STDIO_STREAM_BUFFER_RAVAIL(stream)) {     /* Have buffered? */
44                         return __STDIO_STREAM_BUFFER_GET(stream);
45                 }
46
47                 /* Is this a fake stream for *sscanf? */
48                 if (__STDIO_STREAM_IS_FAKE_VSSCANF(stream)) {
49                         __STDIO_STREAM_SET_EOF(stream);
50                         return EOF;
51                 }
52
53                 /* We need to read from the host environment, so we must
54                  * flush all line buffered streams if the stream is not
55                  * fully buffered. */
56                 if (!__STDIO_STREAM_IS_FBF(stream)) {
57                         __STDIO_FLUSH_LBF_STREAMS;
58                 }
59
60                 if (__STDIO_STREAM_BUFFER_SIZE(stream)) { /* Do we have a buffer? */
61                         __STDIO_STREAM_DISABLE_GETC(stream);
62                         if(__STDIO_FILL_READ_BUFFER(stream)) {  /* Refill succeeded? */
63                                 __STDIO_STREAM_ENABLE_GETC(stream);     /* FBF or LBF */
64                                 return __STDIO_STREAM_BUFFER_GET(stream);
65                         }
66                 } else {
67                         unsigned char uc;
68                         if (__stdio_READ(stream, &uc, 1)) {
69                                 return uc;
70                         }
71                 }
72         }
73
74         return EOF;
75 }
76 libc_hidden_def(__fgetc_unlocked)
77
78 /* libc_hidden_proto(fgetc_unlocked) */
79 strong_alias(__fgetc_unlocked,fgetc_unlocked)
80 libc_hidden_def(fgetc_unlocked)
81
82 //libc_hidden_proto(__getc_unlocked)
83 //strong_alias(__fgetc_unlocked,__getc_unlocked)
84 //libc_hidden_def(__getc_unlocked)
85
86 /* libc_hidden_proto(getc_unlocked) */
87 strong_alias(__fgetc_unlocked,getc_unlocked)
88 libc_hidden_def(getc_unlocked)
89
90 #ifndef __UCLIBC_HAS_THREADS__
91 /* libc_hidden_proto(fgetc) */
92 strong_alias(__fgetc_unlocked,fgetc)
93 libc_hidden_def(fgetc)
94
95 strong_alias(__fgetc_unlocked,getc)
96 #endif
97
98 #elif defined __UCLIBC_HAS_THREADS__
99
100 /* libc_hidden_proto(fgetc) */
101 int fgetc(register FILE *stream)
102 {
103         if (stream->__user_locking != 0) {
104                 return __GETC_UNLOCKED_MACRO(stream);
105         } else {
106                 int retval;
107                 __STDIO_ALWAYS_THREADLOCK(stream);
108                 retval = __GETC_UNLOCKED_MACRO(stream);
109                 __STDIO_ALWAYS_THREADUNLOCK(stream);
110                 return retval;
111         }
112 }
113 libc_hidden_def(fgetc)
114
115 strong_alias(fgetc,getc)
116
117 #endif