extract-control.cc 802 B

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