Index: glibc-2.7/libio/fileops.c =================================================================== --- glibc-2.7.orig/libio/fileops.c 2007-10-23 08:46:13.000000000 -0400 +++ glibc-2.7/libio/fileops.c 2007-10-23 08:50:51.000000000 -0400 @@ -522,10 +522,19 @@ fp->_cur_column = INTUSE(_IO_adjust_column) (fp->_cur_column - 1, data, count) + 1; _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base); - fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base; - fp->_IO_write_end = (fp->_mode <= 0 + if (__builtin_expect (count == to_do, 1)) + { + fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base; + fp->_IO_write_end = (fp->_mode <= 0 && (fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED)) ? fp->_IO_buf_base : fp->_IO_buf_end); + } + else if (count > 0 && fp->_IO_write_base == data) + { + memmove (data, data+count, + fp->_IO_write_ptr - fp->_IO_write_base - count); + fp->_IO_write_ptr -= count; + } return count; }