extract-control.cc 853 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. write(STDOUT_FILENO,Extract.Control,Extract.Length);
  19. return true;
  20. }
  21. int main(int argc, const char *argv[])
  22. {
  23. if (argc < 2)
  24. {
  25. cerr << "Need two arguments, a .deb and the control member" << endl;
  26. return 100;
  27. }
  28. if (ExtractMember(argv[1],argv[2]) == false)
  29. {
  30. _error->DumpErrors();
  31. return 100;
  32. }
  33. return 0;
  34. }