123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- #include "_stdio.h"
- #ifdef __DO_UNLOCKED
- static void munge_stream(register FILE *stream, unsigned char *buf)
- {
- stream->__bufend = stream->__bufstart = buf;
- __STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
- __STDIO_STREAM_DISABLE_GETC(stream);
- __STDIO_STREAM_DISABLE_PUTC(stream);
- }
- wint_t fgetwc_unlocked(register FILE *stream)
- {
- wint_t wi;
- wchar_t wc[1];
- int n;
- size_t r;
- unsigned char sbuf[1];
- __STDIO_STREAM_VALIDATE(stream);
- wi = WEOF;
- if (__STDIO_STREAM_IS_WIDE_READING(stream)
- || !__STDIO_STREAM_TRANS_TO_READ(stream, __FLAG_WIDE)
- ) {
- if (stream->__modeflags & __FLAG_UNGOT) {
- if (((stream->__modeflags & 1) || stream->__ungot[1])) {
- stream->__ungot_width[0] = 0;
- } else {
- stream->__ungot_width[0] = stream->__ungot_width[1];
- }
- wi = stream->__ungot[(stream->__modeflags--) & 1];
- stream->__ungot[1] = 0;
- goto DONE;
- }
- if (!stream->__bufstart) {
-
- munge_stream(stream, sbuf);
- ++stream->__bufend;
- }
- if (stream->__state.__mask == 0) {
- stream->__ungot_width[0] = 0;
- }
- LOOP:
- if ((n = __STDIO_STREAM_BUFFER_RAVAIL(stream)) == 0) {
- goto FILL_BUFFER;
- }
- r = mbrtowc(wc, (const char*) stream->__bufpos, n, &stream->__state);
- if (((ssize_t) r) >= 0) {
- if (r == 0) {
- ++r;
- }
- stream->__bufpos += r;
- stream->__ungot_width[0] += r;
- wi = *wc;
- goto DONE;
- }
- if (r == ((size_t) -2)) {
-
- stream->__bufpos += n;
- stream->__ungot_width[0] += n;
- FILL_BUFFER:
- if(__STDIO_FILL_READ_BUFFER(stream)) {
- goto LOOP;
- }
- if (!__FERROR_UNLOCKED(stream)) {
- if (!stream->__state.__mask) {
- goto DONE;
- }
-
-
- __set_errno(EILSEQ);
- }
- }
-
- stream->__modeflags |= __FLAG_ERROR;
- DONE:
- if (stream->__bufstart == sbuf) {
- munge_stream(stream, NULL);
- }
- }
- __STDIO_STREAM_VALIDATE(stream);
- return wi;
- }
- libc_hidden_def(fgetwc_unlocked)
- strong_alias(fgetwc_unlocked,getwc_unlocked)
- #ifndef __UCLIBC_HAS_THREADS__
- strong_alias(fgetwc_unlocked,fgetwc)
- libc_hidden_def(fgetwc)
- strong_alias(fgetwc_unlocked,getwc)
- #endif
- #elif defined __UCLIBC_HAS_THREADS__
- wint_t fgetwc(register FILE *stream)
- {
- wint_t retval;
- __STDIO_AUTO_THREADLOCK_VAR;
- __STDIO_AUTO_THREADLOCK(stream);
- retval = fgetwc_unlocked(stream);
- __STDIO_AUTO_THREADUNLOCK(stream);
- return retval;
- }
- libc_hidden_def(fgetwc)
- strong_alias(fgetwc,getwc)
- #endif
|