Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.7KB

  1. /*
  2. * Carla binary utils
  3. * Copyright (C) 2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_BINARY_UTILS_HPP_INCLUDED
  18. #define CARLA_BINARY_UTILS_HPP_INCLUDED
  19. #include "CarlaBackend.h"
  20. #include "CarlaUtils.hpp"
  21. #if defined(CARLA_OS_LINUX) && ! defined(BUILD_BRIDGE)
  22. # include "magic.h"
  23. #endif
  24. CARLA_BACKEND_START_NAMESPACE
  25. #if defined(CARLA_OS_LINUX) && ! defined(BUILD_BRIDGE)
  26. // -----------------------------------------------------------------------
  27. class CarlaMagic
  28. {
  29. public:
  30. CarlaMagic()
  31. : fMagic(magic_open(MAGIC_SYMLINK))
  32. {
  33. CARLA_SAFE_ASSERT_RETURN(fMagic != nullptr,);
  34. magic_load(fMagic, nullptr);
  35. }
  36. ~CarlaMagic()
  37. {
  38. if (fMagic != nullptr)
  39. magic_close(fMagic);
  40. }
  41. const char* getFileDescription(const char* const filename) const
  42. {
  43. if (fMagic == nullptr)
  44. return nullptr;
  45. return magic_file(fMagic, filename);
  46. }
  47. private:
  48. const magic_t fMagic;
  49. };
  50. static const CarlaMagic& getCarlaMagicInstance()
  51. {
  52. static CarlaMagic magic;
  53. return magic;
  54. }
  55. #endif
  56. // -----------------------------------------------------------------------
  57. static inline
  58. BinaryType getBinaryTypeFromFile(const char* const filename)
  59. {
  60. carla_stdout("getBinaryTypeFromFile(\"%s\")", filename);
  61. #if defined(CARLA_OS_LINUX) && ! defined(BUILD_BRIDGE)
  62. if (filename == nullptr || filename[0] == '\0')
  63. return BINARY_NATIVE;
  64. const CarlaMagic& magic(getCarlaMagicInstance());
  65. const char* const output(magic.getFileDescription(filename));
  66. if (output == nullptr || output[0] == '\0')
  67. return BINARY_NATIVE;
  68. if (std::strstr(output, "PE32 executable") != nullptr && std::strstr(output, "MS Windows") != nullptr)
  69. return std::strstr(output, "x86-64") != nullptr ? BINARY_WIN64 : BINARY_WIN32;
  70. if (std::strstr(output, "ELF") != nullptr)
  71. return (std::strstr(output, "x86-64") != nullptr || std::strstr(output, "aarch64") != nullptr) ? BINARY_POSIX64 : BINARY_POSIX32;
  72. #endif
  73. return BINARY_NATIVE;
  74. }
  75. // -----------------------------------------------------------------------
  76. CARLA_BACKEND_END_NAMESPACE
  77. #endif // CARLA_BINARY_UTILS_HPP_INCLUDED