1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
2 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
4 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
16 /* libc_hidden_proto(__fgetc_unlocked) */
20 /* libc_hidden_proto(fflush_unlocked) */
22 int __fgetc_unlocked(FILE *stream)
24 __STDIO_STREAM_VALIDATE(stream);
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);
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)
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);
43 if (__STDIO_STREAM_BUFFER_RAVAIL(stream)) { /* Have buffered? */
44 return __STDIO_STREAM_BUFFER_GET(stream);
47 /* Is this a fake stream for *sscanf? */
48 if (__STDIO_STREAM_IS_FAKE_VSSCANF(stream)) {
49 __STDIO_STREAM_SET_EOF(stream);
53 /* We need to read from the host environment, so we must
54 * flush all line buffered streams if the stream is not
56 if (!__STDIO_STREAM_IS_FBF(stream)) {
57 __STDIO_FLUSH_LBF_STREAMS;
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);
68 if (__stdio_READ(stream, &uc, 1)) {
76 libc_hidden_def(__fgetc_unlocked)
78 /* libc_hidden_proto(fgetc_unlocked) */
79 strong_alias(__fgetc_unlocked,fgetc_unlocked)
80 libc_hidden_def(fgetc_unlocked)
82 //libc_hidden_proto(__getc_unlocked)
83 //strong_alias(__fgetc_unlocked,__getc_unlocked)
84 //libc_hidden_def(__getc_unlocked)
86 /* libc_hidden_proto(getc_unlocked) */
87 strong_alias(__fgetc_unlocked,getc_unlocked)
88 libc_hidden_def(getc_unlocked)
90 #ifndef __UCLIBC_HAS_THREADS__
91 /* libc_hidden_proto(fgetc) */
92 strong_alias(__fgetc_unlocked,fgetc)
93 libc_hidden_def(fgetc)
95 strong_alias(__fgetc_unlocked,getc)
98 #elif defined __UCLIBC_HAS_THREADS__
100 /* libc_hidden_proto(fgetc) */
101 int fgetc(register FILE *stream)
103 if (stream->__user_locking != 0) {
104 return __GETC_UNLOCKED_MACRO(stream);
107 __STDIO_ALWAYS_THREADLOCK(stream);
108 retval = __GETC_UNLOCKED_MACRO(stream);
109 __STDIO_ALWAYS_THREADUNLOCK(stream);
113 libc_hidden_def(fgetc)
115 strong_alias(fgetc,getc)