]> git.saurik.com Git - apple/libc.git/blob - stdio/FreeBSD/makebuf.c.patch
Libc-583.tar.gz
[apple/libc.git] / stdio / FreeBSD / makebuf.c.patch
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
4 #include "local.h"
5 #include "un-namespace.h"
6
7 +#define MAXBUFSIZE (1 << 16)
8 +#define TTYBUFSIZE 4096
9 +
10 /*
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)
14 return;
15 }
16 flags = __swhatbuf(fp, &size, &couldbetty);
17 + if (couldbetty && isatty(fp->_file)) {
18 + flags |= __SLBF;
19 + /* st_blksize for ttys is 128K, so make it more reasonable */
20 + if (size > TTYBUFSIZE)
21 + fp->_blksize = size = TTYBUFSIZE;
22 + }
23 if ((p = malloc(size)) == NULL) {
24 fp->_flags |= __SNBF;
25 fp->_bf._base = fp->_p = fp->_nbuf;
26 @@ -81,8 +90,6 @@ __smakebuf(fp)
27 flags |= __SMBF;
28 fp->_bf._base = fp->_p = p;
29 fp->_bf._size = size;
30 - if (couldbetty && isatty(fp->_file))
31 - flags |= __SLBF;
32 fp->_flags |= flags;
33 }
34
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.
38 */
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 ?
43 __SOPT : __SNPT);
44 }