diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2011-12-18 01:21:20 +0100 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2011-12-18 01:21:20 +0100 |
commit | 40468850491c4f5bc7060763a6f03cdc570d514e (patch) | |
tree | dea7735859a45f88e59bb6d584f60886b9a8105d /apt-pkg/contrib/fileutl.cc | |
parent | 109eb1511d0cdfa4af3196105cada30bcbb77bc8 (diff) |
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"
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 34 |
1 files 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) |