extract-control.cc 850 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <apt-pkg/debfile.h>
  2. #include <apt-pkg/error.h>
  3. #include <apt-pkg/fileutl.h>
  4. #include <iostream>
  5. #include <unistd.h>
  6. using namespace std;
  7. bool ExtractMember(const char *File,const char *Member)
  8. {
  9. FileFd Fd(File,FileFd::ReadOnly);
  10. debDebFile Deb(Fd);
  11. if(_error->PendingError() == true)
  12. return false;
  13. debDebFile::MemControlExtract Extract(Member);
  14. if (Extract.Read(Deb) == false)
  15. return false;
  16. if (Extract.Control == 0)
  17. return true;
  18. return write(STDOUT_FILENO,Extract.Control,Extract.Length) != -1;
  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. }