1 --- fread.c.orig 2008-08-29 21:58:50.000000000 -0700
2 +++ fread.c 2008-09-02 02:18:06.000000000 -0700
3 @@ -55,7 +55,7 @@ fread(buf, size, count, fp)
12 @@ -71,21 +71,70 @@ fread(buf, size, count, fp)
16 + /* first deal with anything left in buffer, plus any ungetc buffers */
17 while (resid > (r = fp->_r)) {
18 (void)memcpy((void *)p, (void *)fp->_p, (size_t)r);
20 /* fp->_r = 0 ... done in __srefill */
23 - if (__srefill(fp)) {
24 + if ((ret = __srefill0(fp)) > 0)
27 /* no more input: return partial result */
29 return ((total - resid) / size);
32 - (void)memcpy((void *)p, (void *)fp->_p, resid);
36 + * 5980080: don't use optimization if __SMBF not set (meaning setvbuf
37 + * was called, and the buffer belongs to the user).
38 + * 6180417: but for unbuffered (__SMBF is not set), so specifically
41 + if ((fp->_flags & (__SMBF | __SNBF)) && resid > fp->_bf._size) {
47 + fp->_bf._size = resid;
48 + while (fp->_bf._size > 0) {
49 + if ((ret = __srefill1(fp)) != 0) {
50 + /* no more input: return partial result */
51 + resid = fp->_bf._size;
53 + fp->_p = fp->_bf._base;
54 + /* fp->_r = 0; already set in __srefill1 */
56 + return ((total - resid) / size);
58 + fp->_bf._base += fp->_r;
59 + fp->_bf._size -= fp->_r;
62 + n = fp->_bf._size * ((resid - 1) / fp->_bf._size);
64 + (void)memcpy((void *)fp->_bf._base, (void *)(p + n), (size_t)r);
65 + fp->_p = fp->_bf._base + r;
68 + while (resid > (r = fp->_r)) {
69 + (void)memcpy((void *)p, (void *)fp->_p, (size_t)r);
71 + /* fp->_r = 0 ... done in __srefill */
74 + if (__srefill1(fp)) {
75 + /* no more input: return partial result */
77 + return ((total - resid) / size);
80 + (void)memcpy((void *)p, (void *)fp->_p, resid);