From 40468850491c4f5bc7060763a6f03cdc570d514e Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sun, 18 Dec 2011 01:21:20 +0100 Subject: usage of Skipping in pipes can't work, so we ignore-read instead Also, read only one char in each step of ReadLine instead of back-"seeking" --- apt-pkg/contrib/fileutl.cc | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index bb836e93b..b350973af 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1100,15 +1100,19 @@ char* FileFd::ReadLine(char *To, unsigned long long const Size) #endif unsigned long long read = 0; - if (Read(To, Size, &read) == false) + while ((Size - 1) != read) + { + unsigned long long done = 0; + if (Read(To + read, 1, &done) == false) + return NULL; + if (done == 0) + break; + if (To[read++] == '\n') + break; + } + if (read == 0) return NULL; - char* c = To; - for (; *c != '\n' && *c != '\0' && read != 0; --read, ++c) - ; // find the end of the line - if (*c != '\0') - *c = '\0'; - if (read != 0) - Seek(Tell() - read); + To[read] = '\0'; return To; } /*}}}*/ @@ -1210,6 +1214,20 @@ bool FileFd::Seek(unsigned long long To) /* */ bool FileFd::Skip(unsigned long long Over) { + if (d->pipe == true) + { + d->seekpos += Over; + char buffer[1024]; + while (Over != 0) + { + unsigned long long toread = std::min((unsigned long long) sizeof(buffer), Over); + if (Read(buffer, toread) == false) + return _error->Error("Unable to seek ahead %llu",Over); + Over -= toread; + } + return true; + } + int res; #if APT_USE_ZLIB if (d->gz != NULL) -- cgit v1.2.3