1 --- makebuf.c.orig 2008-08-28 17:18:09.000000000 -0700
2 +++ makebuf.c 2008-09-04 14:20:48.000000000 -0700
3 @@ -49,6 +49,9 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/m
5 #include "un-namespace.h"
7 +#define MAXBUFSIZE (1 << 16)
8 +#define TTYBUFSIZE 4096
11 * Allocate a file buffer, or switch to unbuffered I/O.
12 * Per the ANSI C standard, ALL tty devices default to line buffered.
13 @@ -71,6 +74,12 @@ __smakebuf(fp)
16 flags = __swhatbuf(fp, &size, &couldbetty);
17 + if (couldbetty && isatty(fp->_file)) {
19 + /* st_blksize for ttys is 128K, so make it more reasonable */
20 + if (size > TTYBUFSIZE)
21 + fp->_blksize = size = TTYBUFSIZE;
23 if ((p = malloc(size)) == NULL) {
25 fp->_bf._base = fp->_p = fp->_nbuf;
26 @@ -81,8 +90,6 @@ __smakebuf(fp)
28 fp->_bf._base = fp->_p = p;
30 - if (couldbetty && isatty(fp->_file))
35 @@ -115,8 +122,7 @@ __swhatbuf(fp, bufsize, couldbetty)
36 * __sseek is mainly paranoia.) It is safe to set _blksize
37 * unconditionally; it will only be used if __SOPT is also set.
39 - *bufsize = st.st_blksize;
40 - fp->_blksize = st.st_blksize;
41 + fp->_blksize = *bufsize = st.st_blksize > MAXBUFSIZE ? MAXBUFSIZE : st.st_blksize;
42 return ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ?