summaryrefslogtreecommitdiff
path: root/ftparchive/contents.cc
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 /ftparchive/contents.cc
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 'ftparchive/contents.cc')
-rw-r--r--ftparchive/contents.cc34
1 files changed, 18 insertions, 16 deletions
diff --git a/ftparchive/contents.cc b/ftparchive/contents.cc
index 8c4181eda..145f3910e 100644
--- a/ftparchive/contents.cc
+++ b/ftparchive/contents.cc
@@ -38,6 +38,7 @@
#include <apt-pkg/debfile.h>
#include <apt-pkg/dirstream.h>
#include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -238,19 +239,19 @@ void GenContents::Add(const char *Dir,const char *Package)
// GenContents::WriteSpace - Write a given number of white space chars /*{{{*/
// ---------------------------------------------------------------------
/* We mod 8 it and write tabs where possible. */
-void GenContents::WriteSpace(FILE *Out,unsigned int Current,unsigned int Target)
+void GenContents::WriteSpace(std::string &out, size_t Current, size_t Target)
{
if (Target <= Current)
Target = Current + 1;
-
+
/* Now we write tabs so long as the next tab stop would not pass
the target */
for (; (Current/8 + 1)*8 < Target; Current = (Current/8 + 1)*8)
- fputc('\t',Out);
+ out.append("\t");
// Fill the last bit with spaces
for (; Current < Target; Current++)
- fputc(' ',Out);
+ out.append(" ");
}
/*}}}*/
// GenContents::Print - Display the tree /*{{{*/
@@ -259,13 +260,13 @@ void GenContents::WriteSpace(FILE *Out,unsigned int Current,unsigned int Target)
calls itself and runs over each section of the tree printing out
the pathname and the hit packages. We use Buf to build the pathname
summed over all the directory parents of this node. */
-void GenContents::Print(FILE *Out)
+void GenContents::Print(FileFd &Out)
{
char Buffer[1024];
Buffer[0] = 0;
DoPrint(Out,&Root,Buffer);
}
-void GenContents::DoPrint(FILE *Out,GenContents::Node *Top, char *Buf)
+void GenContents::DoPrint(FileFd &Out,GenContents::Node *Top, char *Buf)
{
if (Top == 0)
return;
@@ -278,26 +279,27 @@ void GenContents::DoPrint(FILE *Out,GenContents::Node *Top, char *Buf)
if (Top->Path != 0)
{
strcat(Buf,Top->Path);
-
+
// Do not show the item if it is a directory with dups
if (Top->Path[strlen(Top->Path)-1] != '/' /*|| Top->Dups == 0*/)
{
- fputs(Buf,Out);
- WriteSpace(Out,strlen(Buf),60);
+ std::string out = Buf;
+ WriteSpace(out, out.length(), 60);
for (Node *I = Top; I != 0; I = I->Dups)
{
if (I != Top)
- fputc(',',Out);
- fputs(I->Package,Out);
+ out.append(",");
+ out.append(I->Package);
}
- fputc('\n',Out);
- }
- }
-
+ out.append("\n");
+ Out.Write(out.c_str(), out.length());
+ }
+ }
+
// Go along the directory link
DoPrint(Out,Top->DirDown,Buf);
*OldEnd = 0;
-
+
// Go right
DoPrint(Out,Top->BTreeRight,Buf);
}