]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-sortpkgs.cc
switch 'apt-mark hold' from Pkg to Ver based operation
[apt.git] / cmdline / apt-sortpkgs.cc
index 971900e4f839d0e806a0ffd5faf48340d2a1ca8b..cde3069bd20550574c0ea667b7230a63f0b388fb 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <iostream>
 #include <string>
+#include <memory>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -108,36 +109,25 @@ static bool DoIt(string InFile)
    const char **Order = TFRewritePackageOrder;
    if (Source == true)
       Order = TFRewriteSourceOrder;
-   
+
    // Emit
-   unsigned char *Buffer = new unsigned char[Largest+1];
+   FileFd stdoutfd;
+   stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false);
+   auto const Buffer = std::unique_ptr<unsigned char[]>(new unsigned char[Largest+1]);
    for (vector<PkgName>::iterator I = List.begin(); I != List.end(); ++I)
    {
       // Read in the Record.
-      if (Fd.Seek(I->Offset) == false || Fd.Read(Buffer,I->Length) == false)
-      {
-        delete [] Buffer;
+      if (Fd.Seek(I->Offset) == false || Fd.Read(Buffer.get(),I->Length) == false)
         return false;
-      }
-      
-      Buffer[I->Length] = '\n';      
-      if (Section.Scan((char *)Buffer,I->Length+1) == false)
-      {
-        delete [] Buffer;
+
+      Buffer[I->Length] = '\n';
+      if (Section.Scan((char *)Buffer.get(),I->Length+1) == false)
         return _error->Error("Internal error, failed to scan buffer");
-      }
 
       // Sort the section
-      if (TFRewrite(stdout,Section,Order,0) == false)
-      {
-        delete [] Buffer;
+      if (Section.Write(stdoutfd, Order) == false || stdoutfd.Write("\n", 1) == false)
         return _error->Error("Internal error, failed to sort fields");
-      }
-      
-      fputc('\n',stdout);      
    }
-   
-   delete [] Buffer;
    return true;
 }
                                                                        /*}}}*/