diff -uNr kdelibs-3.0.2.orig/kate/part/katebuffer.cpp kdelibs-3.0.2/kate/part/katebuffer.cpp --- kdelibs-3.0.2.orig/kate/part/katebuffer.cpp 2002-03-08 09:19:04.000000000 +1000 +++ kdelibs-3.0.2/kate/part/katebuffer.cpp 2002-07-08 06:34:12.000000000 +1000 @@ -38,7 +38,7 @@ // Somewhat smaller than 8192 so that it will still fit in 8192 after we add // some overhead. -#define AVG_BLOCK_SIZE 8000 +#define AVG_BLOCK_SIZE 7000 /** @@ -68,6 +68,8 @@ QByteArray result(size); int bytesToRead = size; int bytesRead = 0; + const char *p; + while(bytesToRead) { int n = ::read(fd, result.data()+bytesRead, bytesToRead); @@ -82,6 +84,30 @@ bytesRead += n; bytesToRead -= n; } + + // Limit reached. However we want to read until newline as chop + // to half line will corrupt any multibyte file. + // + // Point to last character + p = result.data() + bytesRead - 1; + while(*p != '\n') + { + //resize the array before read fd + result.resize(bytesRead+1); + int n = ::read(fd, result.data()+bytesRead, 1); + if (n == 0) break; // Done + if ((n == -1) && (errno == EAGAIN)) + continue; + if (n == -1) + { + // TODO: Do some error handling. + break; + } + // increment bytesRead and pointer + bytesRead += n; + p += n; + } + //kdDebug(13020)<<"Read = "<< bytesRead<fd, blockSize); - eof = ((int) currentBlock.size()) != blockSize; + // it is end of file if the current block size is < blockSize + eof = ((int) currentBlock.size()) < blockSize; KateBufBlock *block = new KateBufBlock(state); m_blocks.insert(loader->blockNr++, block); m_loadedBlocks.append(block);