summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-05-11 15:08:08 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-05-11 17:22:33 +0200
commit88593886a42025d51d76051da5929b044e42efee (patch)
tree6212ec08e3ac872573ca5faefb400a7914051bee /cmdline
parent8d058ea53b18348f81229049a27d14282bd8d8c1 (diff)
rewrite all TFRewrite instances to use the new pkgTagSection::Write
While it is mostly busywork to rewrite all instances it actually fixes bugs as the data storage used by the new method is std::string rather than a char*, the later mostly created by c_str() from a std::string which the caller has to ensure keeps in scope – something apt-ftparchive actually didn't ensure and relied on copy-on-write behavior instead which c++11 forbids and hence the new default gcc abi doesn't use it.
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/apt-cache.cc21
-rw-r--r--cmdline/apt-sortpkgs.cc14
2 files changed, 19 insertions, 16 deletions
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc
index e2cf7e8b7..690b03bcc 100644
--- a/cmdline/apt-cache.cc
+++ b/cmdline/apt-cache.cc
@@ -580,6 +580,12 @@ static bool DumpAvail(CommandLine &)
LocalitySort(VFList,Count,sizeof(*VFList));
+ std::vector<pkgTagSection::Tag> RW;
+ RW.push_back(pkgTagSection::Tag::Remove("Status"));
+ RW.push_back(pkgTagSection::Tag::Remove("Config-Version"));
+ FileFd stdoutfd;
+ stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false);
+
// Iterate over all the package files and write them out.
char *Buffer = new char[Cache->HeaderP->MaxVerFileSize+10];
for (pkgCache::VerFile **J = VFList; *J != 0;)
@@ -620,35 +626,32 @@ static bool DumpAvail(CommandLine &)
if (PkgF.Read(Buffer,VF.Size + Jitter) == false)
break;
Buffer[VF.Size + Jitter] = '\n';
-
+
// See above..
if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource)
{
pkgTagSection Tags;
- TFRewriteData RW[] = {{"Status", NULL, NULL},{"Config-Version", NULL, NULL},{NULL, NULL, NULL}};
- const char *Zero = 0;
if (Tags.Scan(Buffer+Jitter,VF.Size+1) == false ||
- TFRewrite(stdout,Tags,&Zero,RW) == false)
+ Tags.Write(stdoutfd, NULL, RW) == false ||
+ stdoutfd.Write("\n", 1) == false)
{
_error->Error("Internal Error, Unable to parse a package record");
break;
}
- fputc('\n',stdout);
}
else
{
- if (fwrite(Buffer+Jitter,VF.Size+1,1,stdout) != 1)
+ if (stdoutfd.Write(Buffer + Jitter, VF.Size + 1) == false)
break;
}
-
+
Pos = VF.Offset + VF.Size;
}
- fflush(stdout);
if (_error->PendingError() == true)
break;
}
-
+
delete [] Buffer;
delete [] VFList;
return !_error->PendingError();
diff --git a/cmdline/apt-sortpkgs.cc b/cmdline/apt-sortpkgs.cc
index 971900e4f..12ef8dda0 100644
--- a/cmdline/apt-sortpkgs.cc
+++ b/cmdline/apt-sortpkgs.cc
@@ -108,8 +108,10 @@ static bool DoIt(string InFile)
const char **Order = TFRewritePackageOrder;
if (Source == true)
Order = TFRewriteSourceOrder;
-
+
// Emit
+ FileFd stdoutfd;
+ stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false);
unsigned char *Buffer = new unsigned char[Largest+1];
for (vector<PkgName>::iterator I = List.begin(); I != List.end(); ++I)
{
@@ -119,8 +121,8 @@ static bool DoIt(string InFile)
delete [] Buffer;
return false;
}
-
- Buffer[I->Length] = '\n';
+
+ Buffer[I->Length] = '\n';
if (Section.Scan((char *)Buffer,I->Length+1) == false)
{
delete [] Buffer;
@@ -128,15 +130,13 @@ static bool DoIt(string InFile)
}
// Sort the section
- if (TFRewrite(stdout,Section,Order,0) == false)
+ if (Section.Write(stdoutfd, Order) == false || stdoutfd.Write("\n", 1) == false)
{
delete [] Buffer;
return _error->Error("Internal error, failed to sort fields");
}
-
- fputc('\n',stdout);
}
-
+
delete [] Buffer;
return true;
}