Utils_Linux.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Utils/Utils.h>
  9. #include <sys/types.h>
  10. #include <sys/wait.h>
  11. #include <AzCore/PlatformIncl.h>
  12. namespace AtomSampleViewer
  13. {
  14. namespace Utils
  15. {
  16. bool SupportsResizeClientArea()
  17. {
  18. return true;
  19. }
  20. AZStd::string GetDefaultDiffToolPath_Impl()
  21. {
  22. return AZStd::string("/usr/bin/bcompare");
  23. }
  24. bool RunDiffTool_Impl(const AZStd::string& diffToolPath, const AZStd::string& filePathA, const AZStd::string& filePathB)
  25. {
  26. bool result = true;
  27. // Fork a process to run Beyond Compare app
  28. pid_t childPid = fork();
  29. if (childPid == 0)
  30. {
  31. // In child process
  32. char* args[] = { const_cast<char*>(diffToolPath.c_str()), const_cast<char*>(filePathA.c_str()),
  33. const_cast<char*>(filePathB.c_str()), static_cast<char*>(0) };
  34. execv(diffToolPath.c_str(), args);
  35. AZ_Error(
  36. "RunDiffTool", false,
  37. "RunDiffTool: Unable to launch Diff Tool %s : errno = %s .",
  38. diffToolPath.c_str(), strerror(errno));
  39. _exit(errno);
  40. }
  41. else if (childPid > 0)
  42. {
  43. // In parent process
  44. int status;
  45. pid_t result = waitpid(childPid, &status, WNOHANG);
  46. if (result == -1)
  47. {
  48. result = false;
  49. }
  50. }
  51. else
  52. {
  53. result = false;
  54. }
  55. return result;
  56. }
  57. } // namespace Utils
  58. } // namespace AtomSampleViewer