1 --- makebuf.c.bsdnew 2009-11-11 13:33:12.000000000 -0800
2 +++ makebuf.c 2009-11-11 13:33:13.000000000 -0800
3 @@ -47,6 +47,9 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/m
4 #include "libc_private.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 @@ -69,6 +72,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 @@ -79,8 +88,6 @@ __smakebuf(fp)
28 fp->_bf._base = fp->_p = p;
30 - if (couldbetty && isatty(fp->_file))
35 @@ -113,8 +120,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 ?