Merge remote-tracking branch 'donkult/debian/sid' into debian/sid
[ntk/apt.git] / test / interactive-helper / extract-control.cc
1 #include <apt-pkg/debfile.h>
2 #include <apt-pkg/error.h>
3 #include <apt-pkg/fileutl.h>
4
5 #include <iostream>
6 #include <unistd.h>
7
8 using namespace std;
9
10 bool ExtractMember(const char *File,const char *Member)
11 {
12 FileFd Fd(File,FileFd::ReadOnly);
13 debDebFile Deb(Fd);
14 if(_error->PendingError() == true)
15 return false;
16
17 debDebFile::MemControlExtract Extract(Member);
18 if (Extract.Read(Deb) == false)
19 return false;
20
21 if (Extract.Control == 0)
22 return true;
23
24 return write(STDOUT_FILENO,Extract.Control,Extract.Length) != -1;
25 }
26
27 int main(int argc, const char *argv[])
28 {
29 if (argc < 2)
30 {
31 cerr << "Need two arguments, a .deb and the control member" << endl;
32 return 100;
33 }
34
35 if (ExtractMember(argv[1],argv[2]) == false)
36 {
37 _error->DumpErrors();
38 return 100;
39 }
40
41 return 0;
42 }