summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/mmap.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2012-06-29 15:34:12 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2012-06-29 15:34:12 +0200
commit7ac4503f3e0ccf0fbad592179331c0f1bba427a5 (patch)
tree67930f70476dfc80d85e228d1f8efa3dc276947a /apt-pkg/contrib/mmap.cc
parent7cb48e888df3f4a7156d39515e6573aed66acd39 (diff)
parent545ba6bdd8cb77ceca6b9fdc935db2accbea3493 (diff)
merged from the debian-sid branch
Diffstat (limited to 'apt-pkg/contrib/mmap.cc')
-rw-r--r--apt-pkg/contrib/mmap.cc20
1 files changed, 11 insertions, 9 deletions
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc
index 2d12b6fe9..593bb063b 100644
--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -83,7 +83,7 @@ bool MMap::Map(FileFd &Fd)
{
if ((Flags & ReadOnly) != ReadOnly)
return _error->Error("Compressed file %s can only be mapped readonly", Fd.Name().c_str());
- Base = new unsigned char[iSize];
+ Base = malloc(iSize);
SyncToFd = new FileFd();
if (Fd.Seek(0L) == false || Fd.Read(Base, iSize) == false)
return _error->Error("Compressed file %s can't be read into mmap", Fd.Name().c_str());
@@ -91,17 +91,17 @@ bool MMap::Map(FileFd &Fd)
}
// Map it.
- Base = mmap(0,iSize,Prot,Map,Fd.Fd(),0);
+ Base = (Flags & Fallback) ? MAP_FAILED : mmap(0,iSize,Prot,Map,Fd.Fd(),0);
if (Base == (void *)-1)
{
- if (errno == ENODEV || errno == EINVAL)
+ if (errno == ENODEV || errno == EINVAL || (Flags & Fallback))
{
// The filesystem doesn't support this particular kind of mmap.
// So we allocate a buffer and read the whole file into it.
if ((Flags & ReadOnly) == ReadOnly)
{
// for readonly, we don't need sync, so make it simple
- Base = new unsigned char[iSize];
+ Base = malloc(iSize);
return Fd.Read(Base, iSize);
}
// FIXME: Writing to compressed fd's ?
@@ -109,7 +109,7 @@ bool MMap::Map(FileFd &Fd)
if (dupped_fd == -1)
return _error->Errno("mmap", _("Couldn't duplicate file descriptor %i"), Fd.Fd());
- Base = new unsigned char[iSize];
+ Base = calloc(iSize, 1);
SyncToFd = new FileFd (dupped_fd);
if (!SyncToFd->Seek(0L) || !SyncToFd->Read(Base, iSize))
return false;
@@ -135,7 +135,7 @@ bool MMap::Close(bool DoSync)
if (SyncToFd != NULL)
{
- delete[] (char *)Base;
+ free(Base);
delete SyncToFd;
SyncToFd = NULL;
}
@@ -283,8 +283,7 @@ DynamicMMap::DynamicMMap(unsigned long Flags,unsigned long const &WorkSpace,
}
#endif
// fallback to a static allocated space
- Base = new unsigned char[WorkSpace];
- memset(Base,0,WorkSpace);
+ Base = calloc(WorkSpace, 1);
iSize = 0;
}
/*}}}*/
@@ -300,7 +299,7 @@ DynamicMMap::~DynamicMMap()
#ifdef _POSIX_MAPPED_FILES
munmap(Base, WorkSpace);
#else
- delete [] (unsigned char *)Base;
+ free(Base);
#endif
return;
}
@@ -464,6 +463,9 @@ bool DynamicMMap::Grow() {
Base = realloc(Base, newSize);
if (Base == NULL)
return false;
+ else
+ /* Set new memory to 0 */
+ memset((char*)Base + WorkSpace, 0, newSize - WorkSpace);
}
Pools =(Pool*) Base + poolOffset;