12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include "_stdio.h"
- #ifdef __UCLIBC_HAS_WCHAR__
- int attribute_hidden __stdio_trans2r_o(FILE * __restrict stream, int oflag)
- #else
- int attribute_hidden __stdio_trans2r(FILE * __restrict stream)
- #endif
- {
- __STDIO_STREAM_VALIDATE(stream);
- assert(!__STDIO_STREAM_IS_READING(stream));
- #ifdef __UCLIBC_HAS_WCHAR__
- if (!(stream->__modeflags & oflag)) {
- if (stream->__modeflags & (__FLAG_NARROW|__FLAG_WIDE)) {
- __UNDEFINED_OR_NONPORTABLE;
- goto DO_EBADF;
- }
- stream->__modeflags |= oflag;
- }
- #endif
- if (stream->__modeflags & __FLAG_WRITEONLY) {
- #if defined(__UCLIBC_HAS_WCHAR__) || !defined(__UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__)
- DO_EBADF:
- #endif
- __set_errno(EBADF);
- #ifdef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__
- ERROR:
- #endif
- __STDIO_STREAM_SET_ERROR(stream);
- __STDIO_STREAM_VALIDATE(stream);
- return EOF;
- }
- if (__STDIO_STREAM_IS_WRITING(stream)) {
- #ifdef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__
- if (__STDIO_COMMIT_WRITE_BUFFER(stream)) {
- goto ERROR;
- }
- assert(!__STDIO_STREAM_BUFFER_WUSED(stream));
- __STDIO_STREAM_DISABLE_PUTC(stream);
- __STDIO_STREAM_CLEAR_WRITING(stream);
- #else
-
- __UNDEFINED_OR_NONPORTABLE;
- goto DO_EBADF;
- #endif
- }
- __STDIO_STREAM_SET_READING(stream);
-
- __STDIO_STREAM_VALIDATE(stream);
- return 0;
- }
|