12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #include "_stdio.h"
- #ifdef __UCLIBC_HAS_WCHAR__
- int attribute_hidden __stdio_trans2w_o(FILE * __restrict stream, int oflag)
- #else
- int attribute_hidden __stdio_trans2w(FILE * __restrict stream)
- #endif
- {
- __STDIO_STREAM_VALIDATE(stream);
- assert(!__STDIO_STREAM_IS_WRITING(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_READONLY) {
- #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_READING(stream)) {
- if (!__FEOF_UNLOCKED(stream)) {
- #ifdef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__
-
- if (((__STDIO_STREAM_BUFFER_RAVAIL(stream))
- || (stream->__modeflags & __FLAG_UNGOT))
- && fseek(stream, 0L,
- ((stream->__modeflags & __FLAG_APPEND)
- ? SEEK_END : SEEK_CUR))
- ) {
-
- goto ERROR;
- }
- #else
-
- __UNDEFINED_OR_NONPORTABLE;
- goto DO_EBADF;
- #endif
- }
- __STDIO_STREAM_CLEAR_READING_AND_UNGOTS(stream);
- __STDIO_STREAM_DISABLE_GETC(stream);
-
- __STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
- }
- __STDIO_STREAM_SET_WRITING(stream);
- if (__STDIO_STREAM_IS_NARROW_FBF(stream)) {
- __STDIO_STREAM_ENABLE_PUTC(stream);
- }
- __STDIO_STREAM_VALIDATE(stream);
- return 0;
- }
|