1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
10 /* Function to handle transition to reading.
11 * Initialize or verify the stream's orientation (even if writeonly).
12 * Check that the stream is readable.
13 * If currently reading, check that we can transition to writing.
14 * C99 requires that we not be reading, but attempting to
15 * auto-transition by commiting the write buffer is a configurable
17 * Returns 0 on success and EOF otherwise.
20 * There are two function signatures, depending on wchar support,
21 * since with no wchar support the orientation is narrow by default.
24 #ifdef __UCLIBC_HAS_WCHAR__
25 int attribute_hidden
__stdio_trans2r_o(FILE * __restrict stream
, int oflag
)
27 int attribute_hidden
__stdio_trans2r(FILE * __restrict stream
)
30 __STDIO_STREAM_VALIDATE(stream
);
31 assert(!__STDIO_STREAM_IS_READING(stream
));
33 #ifdef __UCLIBC_HAS_WCHAR__
34 if (!(stream
->__modeflags
& oflag
)) {
35 if (stream
->__modeflags
& (__FLAG_NARROW
|__FLAG_WIDE
)) {
36 __UNDEFINED_OR_NONPORTABLE
;
39 stream
->__modeflags
|= oflag
;
43 if (stream
->__modeflags
& __FLAG_WRITEONLY
) {
44 #if defined(__UCLIBC_HAS_WCHAR__) || !defined(__UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__)
48 #ifdef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__
51 __STDIO_STREAM_SET_ERROR(stream
);
52 __STDIO_STREAM_VALIDATE(stream
);
56 if (__STDIO_STREAM_IS_WRITING(stream
)) {
57 #ifdef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__
58 if (__STDIO_COMMIT_WRITE_BUFFER(stream
)) { /* commit failed! */
61 assert(!__STDIO_STREAM_BUFFER_WUSED(stream
));
63 __STDIO_STREAM_DISABLE_PUTC(stream
);
64 __STDIO_STREAM_CLEAR_WRITING(stream
);
66 /* C99: Output shall not be directly followed by input without an
67 intervening call to the fflush function or to a file positioning
68 function (fseek, fsetpos, or rewind). */
69 __UNDEFINED_OR_NONPORTABLE
;
74 __STDIO_STREAM_SET_READING(stream
);
75 /* getc macro is enabled when data is read into buffer. */
77 __STDIO_STREAM_VALIDATE(stream
);