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
10 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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(HAVE_LIBMAGIC) && ! defined(BUILD_BRIDGE)
  22. # include <magic.h>
  23. #endif
  24. CARLA_BACKEND_START_NAMESPACE
  25. #if defined(HAVE_LIBMAGIC) && ! 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_CLASS(CarlaMagic)
  51. };
  52. #endif
  53. // -----------------------------------------------------------------------
  54. static inline
  55. BinaryType getBinaryTypeFromFile(const char* const filename)
  56. {
  57. carla_debug("getBinaryTypeFromFile(\"%s\")", filename);
  58. if (filename == nullptr || filename[0] == '\0')
  59. return BINARY_NATIVE;
  60. #if defined(HAVE_LIBMAGIC) && ! defined(BUILD_BRIDGE)
  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, "MS Windows") != nullptr)
  66. if (std::strstr(output, "PE32 executable") != nullptr || std::strstr(output, "PE32+ executable") != nullptr)
  67. return (std::strstr(output, "x86-64") != nullptr) ? BINARY_WIN64 : BINARY_WIN32;
  68. if (std::strstr(output, "ELF") != nullptr)
  69. return (std::strstr(output, "x86-64") != nullptr || std::strstr(output, "aarch64") != nullptr) ? BINARY_POSIX64 : BINARY_POSIX32;
  70. #endif
  71. return BINARY_NATIVE;
  72. }
  73. // -----------------------------------------------------------------------
  74. CARLA_BACKEND_END_NAMESPACE
  75. #endif // CARLA_BINARY_UTILS_HPP_INCLUDED