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.

104 lines
2.8KB

  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. CARLA_PREVENT_HEAP_ALLOCATION
  50. CARLA_DECLARE_NON_COPY_STRUCT(CarlaMagic)
  51. };
  52. static const CarlaMagic& getCarlaMagicInstance()
  53. {
  54. static CarlaMagic magic;
  55. return magic;
  56. }
  57. #endif
  58. // -----------------------------------------------------------------------
  59. static inline
  60. BinaryType getBinaryTypeFromFile(const char* const filename)
  61. {
  62. carla_stdout("getBinaryTypeFromFile(\"%s\")", filename);
  63. #if defined(CARLA_OS_LINUX) && ! defined(BUILD_BRIDGE)
  64. if (filename == nullptr || filename[0] == '\0')
  65. return BINARY_NATIVE;
  66. const CarlaMagic& magic(getCarlaMagicInstance());
  67. const char* const output(magic.getFileDescription(filename));
  68. if (output == nullptr || output[0] == '\0')
  69. return BINARY_NATIVE;
  70. if (std::strstr(output, "PE32 executable") != nullptr && std::strstr(output, "MS Windows") != nullptr)
  71. return std::strstr(output, "x86-64") != nullptr ? BINARY_WIN64 : BINARY_WIN32;
  72. if (std::strstr(output, "ELF") != nullptr)
  73. return (std::strstr(output, "x86-64") != nullptr || std::strstr(output, "aarch64") != nullptr) ? BINARY_POSIX64 : BINARY_POSIX32;
  74. #endif
  75. return BINARY_NATIVE;
  76. }
  77. // -----------------------------------------------------------------------
  78. CARLA_BACKEND_END_NAMESPACE
  79. #endif // CARLA_BINARY_UTILS_HPP_INCLUDED