1 --- fflush.c.bsdnew 2009-11-11 13:33:04.000000000 -0800
2 +++ fflush.c 2009-11-11 13:33:04.000000000 -0800
3 @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/f
8 #include "un-namespace.h"
9 #include "libc_private.h"
11 @@ -122,6 +123,14 @@ __sflush(FILE *fp)
12 for (; n > 0; n -= t, p += t) {
13 t = _swrite(fp, (char *)p, n);
15 + /* 5340694: reset _p and _w on EAGAIN */
16 + if (t < 0 && errno == EAGAIN) {
17 + if (p > fp->_p) /* some was written */
18 + memmove(fp->_p, p, n);
20 + if (!(fp->_flags & (__SLBF|__SNBF)))