X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fstdio%2F__overflow.c;h=3bb37923abb847787878cf868d86bce570fb267e;hp=e35104deb001de5a0ea2b67d0531a36af4bdd0b4;hb=e3cd6c5c265cd481db6e0c5b529855d99f0bda30;hpb=ea343364a719add2cd8adf8a50c15bb5f9400dd8 diff --git a/src/stdio/__overflow.c b/src/stdio/__overflow.c index e35104de..3bb37923 100644 --- a/src/stdio/__overflow.c +++ b/src/stdio/__overflow.c @@ -1,52 +1,10 @@ #include "stdio_impl.h" -static int overflow(FILE *f, int c) +int __overflow(FILE *f, int _c) { - /* Initialize if we're not already writing */ - if (!f->wend) { - /* Fail if we're in error state or unwritable. */ - if (f->flags & (F_ERR|F_NOWR)) return EOF; - - /* Set byte orientation -1,0=>-1; 1=>1 */ - f->mode |= f->mode-1; - - /* Clear read buffer (easier than summoning nasal demons) */ - f->rpos = f->rend = f->rstop = 0; - - /* Activate write through the buffer */ - f->wpos = f->wbase = f->buf; - f->wend = f->buf + f->buf_size; - f->wstop = (f->lbf < 0) ? f->wend - 1 : 0; - } - - /* Buffer can always hold at least 1 byte... */ - if (c != EOF) { - *f->wpos++ = c; - if (f->wpos <= f->wstop && c != f->lbf) return c; - } - /* ...since if the next call fails, buffer is empty. */ - if (f->write(f, f->wbase, f->wpos - f->wbase) < 0) { - f->flags |= F_ERR; - f->wpos = f->wbase = f->wend = f->wstop = 0; - return EOF; - } - - /* Buffer is empty so reset position to beginning */ - f->wpos = f->wbase; - + unsigned char c = _c; + if (!f->wend && __towrite(f)) return EOF; + if (f->wpos < f->wend && c != f->lbf) return *f->wpos++ = c; + if (f->write(f, &c, 1)!=1) return EOF; return c; } - -int __overflow(FILE *f, int c) -{ - return overflow(f, c & 0xff); -} - -int __oflow(FILE *f) -{ - overflow(f, EOF); - return (f->flags & F_ERR) ? EOF : 0; -} - -/* Link flush-on-exit code iff any stdio write functions are linked. */ -int (*const __fflush_on_exit)(FILE *) = fflush;