extract-control.cc 824 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <apt-pkg/debfile.h>
  2. #include <apt-pkg/error.h>
  3. #include <iostream>
  4. #include <unistd.h>
  5. using namespace std;
  6. bool ExtractMember(const char *File,const char *Member)
  7. {
  8. FileFd Fd(File,FileFd::ReadOnly);
  9. debDebFile Deb(Fd);
  10. if(_error->PendingError() == true)
  11. return false;
  12. debDebFile::MemControlExtract Extract(Member);
  13. if (Extract.Read(Deb) == false)
  14. return false;
  15. if (Extract.Control == 0)
  16. return true;
  17. write(STDOUT_FILENO,Extract.Control,Extract.Length);
  18. return true;
  19. }
  20. int main(int argc, const char *argv[])
  21. {
  22. if (argc < 2)
  23. {
  24. cerr << "Need two arguments, a .deb and the control member" << endl;
  25. return 100;
  26. }
  27. if (ExtractMember(argv[1],argv[2]) == false)
  28. {
  29. _error->DumpErrors();
  30. return 100;
  31. }
  32. return 0;
  33. }