extract-control.cc 896 B

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