diff options
Diffstat (limited to 'data/_apt7/mmap.diff')
-rw-r--r-- | data/_apt7/mmap.diff | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/data/_apt7/mmap.diff b/data/_apt7/mmap.diff new file mode 100644 index 000000000..06f4dbac0 --- /dev/null +++ b/data/_apt7/mmap.diff @@ -0,0 +1,199 @@ +diff -ru apt-0.7.20.2/apt-pkg/tagfile.cc apt-0.7.20.2+iPhone/apt-pkg/tagfile.cc +--- apt-0.7.20.2/apt-pkg/tagfile.cc 2009-04-19 02:42:49.000000000 +0000 ++++ apt-0.7.20.2+iPhone/apt-pkg/tagfile.cc 2009-04-19 03:28:33.000000000 +0000 +@@ -28,11 +28,12 @@ + // --------------------------------------------------------------------- + /* */ + pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long Size) : +- Fd(*pFd), +- Size(Size) ++ Fd(*pFd) + { +- if (Fd.IsOpen() == false) ++ if (Fd.IsOpen() == false || Fd.Size() == 0) + { ++ _error->Discard(); ++ Map = NULL; + Buffer = 0; + Start = End = Buffer = 0; + Done = true; +@@ -40,7 +40,8 @@ + return; + } + +- Buffer = new char[Size]; ++ Map = new MMap(*pFd, MMap::ReadOnly); ++ Buffer = reinterpret_cast<char *>(Map->Data()); + Start = End = Buffer; + Done = false; + iOffset = 0; +@@ -52,36 +53,9 @@ + /* */ + pkgTagFile::~pkgTagFile() + { +- delete [] Buffer; ++ delete Map; + } + /*}}}*/ +-// TagFile::Resize - Resize the internal buffer /*{{{*/ +-// --------------------------------------------------------------------- +-/* Resize the internal buffer (double it in size). Fail if a maximum size +- * size is reached. +- */ +-bool pkgTagFile::Resize() +-{ +- char *tmp; +- unsigned long EndSize = End - Start; +- +- // fail is the buffer grows too big +- if(Size > 1024*1024+1) +- return false; +- +- // get new buffer and use it +- tmp = new char[2*Size]; +- memcpy(tmp, Buffer, Size); +- Size = Size*2; +- delete [] Buffer; +- Buffer = tmp; +- +- // update the start/end pointers to the new buffer +- Start = Buffer; +- End = Start + EndSize; +- return true; +-} +- + // TagFile::Step - Advance to the next section /*{{{*/ + // --------------------------------------------------------------------- + /* If the Section Scanner fails we refill the buffer and try again. +@@ -90,15 +64,11 @@ + */ + bool pkgTagFile::Step(pkgTagSection &Tag) + { +- while (Tag.Scan(Start,End - Start) == false) ++ if (Tag.Scan(Start,End - Start) == false) + { +- if (Fill() == false) +- return false; +- +- if(Tag.Scan(Start,End - Start)) +- break; +- +- if (Resize() == false) ++ if (Start == End) ++ return false; ++ else + return _error->Error(_("Unable to parse package file %s (1)"), + Fd.Name().c_str()); + } +@@ -115,41 +85,11 @@ + then fills the rest from the file */ + bool pkgTagFile::Fill() + { +- unsigned long EndSize = End - Start; +- unsigned long Actual = 0; +- +- memmove(Buffer,Start,EndSize); +- Start = Buffer; +- End = Buffer + EndSize; +- +- if (Done == false) +- { +- // See if only a bit of the file is left +- if (Fd.Read(End,Size - (End - Buffer),&Actual) == false) +- return false; +- if (Actual != Size - (End - Buffer)) +- Done = true; +- End += Actual; +- } +- +- if (Done == true) +- { +- if (EndSize <= 3 && Actual == 0) +- return false; +- if (Size - (End - Buffer) < 4) +- return true; +- +- // Append a double new line if one does not exist +- unsigned int LineCount = 0; +- for (const char *E = End - 1; E - End < 6 && (*E == '\n' || *E == '\r'); E--) +- if (*E == '\n') +- LineCount++; +- for (; LineCount < 2; LineCount++) +- *End++ = '\n'; +- +- return true; +- } +- ++ unsigned int Size(Map->Size()); ++ End = Buffer + Size; ++ if (iOffset >= Size) ++ return false; ++ Start = Buffer + iOffset; + return true; + } + /*}}}*/ +@@ -171,20 +111,11 @@ + // Reposition and reload.. + iOffset = Offset; + Done = false; +- if (Fd.Seek(Offset) == false) +- return false; + End = Start = Buffer; + + if (Fill() == false) + return false; + +- if (Tag.Scan(Start,End - Start) == true) +- return true; +- +- // This appends a double new line (for the real eof handling) +- if (Fill() == false) +- return false; +- + if (Tag.Scan(Start,End - Start) == false) + return _error->Error(_("Unable to parse package file %s (2)"),Fd.Name().c_str()); + +@@ -228,14 +161,16 @@ + + Stop = (const char *)memchr(Stop,'\n',End - Stop); + +- if (Stop == 0) +- return false; ++ if (Stop == 0) { ++ Stop = End; ++ goto end; ++ } + + for (; Stop+1 < End && Stop[1] == '\r'; Stop++); + + // Double newline marks the end of the record +- if (Stop+1 < End && Stop[1] == '\n') +- { ++ if (Stop+1 == End || Stop[1] == '\n') ++ end: { + Indexes[TagCount] = Stop - Section; + for (; Stop < End && (Stop[0] == '\n' || Stop[0] == '\r'); Stop++); + return true; +diff -ru apt-0.7.20.2/apt-pkg/tagfile.h apt-0.7.20.2+iPhone/apt-pkg/tagfile.h +--- apt-0.7.20.2/apt-pkg/tagfile.h 2009-02-07 15:09:35.000000000 +0000 ++++ apt-0.7.20.2+iPhone/apt-pkg/tagfile.h 2009-04-19 03:04:07.000000000 +0000 +@@ -21,6 +21,7 @@ + #define PKGLIB_TAGFILE_H + + ++#include <apt-pkg/mmap.h> + #include <apt-pkg/fileutl.h> + #include <stdio.h> + +@@ -71,10 +72,9 @@ + char *End; + bool Done; + unsigned long iOffset; +- unsigned long Size; ++ MMap *Map; + + bool Fill(); +- bool Resize(); + + public: + |