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.

CarlaBinaryUtils.hpp 2.7KB

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