123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include "_stdio.h"
- #ifdef __UCLIBC_HAS_WCHAR__
- int __stdio_trans2w_o(FILE * __restrict stream, int oflag)
- #else
- int __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;
- }
|