12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include "_stdio.h"
- int ungetc(int c, register FILE *stream)
- {
- __STDIO_AUTO_THREADLOCK_VAR;
- __STDIO_AUTO_THREADLOCK(stream);
- __STDIO_STREAM_VALIDATE(stream);
- #ifdef __UCLIBC_MJN3_ONLY__
- #warning CONSIDER: Make fast ungetc an option?
- #endif
- #ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
-
-
- if (__STDIO_STREAM_CAN_USE_BUFFER_GET(stream)
- && (c != EOF)
- && (stream->__bufpos > stream->__bufstart)
- && (stream->__bufpos[-1] == ((unsigned char)c))
- ) {
- --stream->__bufpos;
- __STDIO_STREAM_CLEAR_EOF(stream);
- } else
- #endif
-
- if ((!__STDIO_STREAM_IS_NARROW_READING(stream)
- && __STDIO_STREAM_TRANS_TO_READ(stream, __FLAG_NARROW))
- || ((stream->__modeflags & __FLAG_UNGOT)
- && ((stream->__modeflags & 1) || stream->__ungot[1]))
- ) {
- c = EOF;
- } else if (c != EOF) {
- __STDIO_STREAM_DISABLE_GETC(stream);
-
- stream->__ungot[1] = 1;
- stream->__ungot[(++stream->__modeflags) & 1] = c;
- __STDIO_STREAM_CLEAR_EOF(stream);
- }
- __STDIO_STREAM_VALIDATE(stream);
- __STDIO_AUTO_THREADUNLOCK(stream);
- return c;
- }
- libc_hidden_def(ungetc)
|