1 #include "stdio_impl.h"
3 static int overflow(FILE *f, int c)
5 /* Initialize if we're not already writing */
7 /* Fail if we're in error state or unwritable. */
8 if (f->flags & (F_ERR|F_NOWR)) return EOF;
10 /* Set byte orientation -1,0=>-1; 1=>1 */
13 /* Clear read buffer (easier than summoning nasal demons) */
14 f->rpos = f->rend = f->rstop = 0;
16 /* Activate write through the buffer */
17 f->wpos = f->wbase = f->buf;
18 f->wend = f->buf + f->buf_size;
19 f->wstop = (f->lbf < 0) ? f->wend - 1 : 0;
22 /* Buffer can always hold at least 1 byte... */
25 if (f->wpos <= f->wstop && c != f->lbf) return c;
27 /* ...since if the next call fails, buffer is empty. */
28 if (f->write(f, f->wbase, f->wpos - f->wbase) < 0) {
30 f->wpos = f->wbase = f->wend = f->wstop = 0;
34 /* Buffer is empty so reset position to beginning */
40 int __overflow(FILE *f, int c)
42 return overflow(f, c & 0xff);
48 return (f->flags & F_ERR) ? EOF : 0;
51 /* Link flush-on-exit code iff any stdio write functions are linked. */
52 int (*const __fflush_on_exit)(FILE *) = fflush;