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.

71 lines
2.1KB

  1. /*
  2. * Cross-platform C++ library for Carla, based on Juce v4
  3. * Copyright (C) 2015 ROLI Ltd.
  4. * Copyright (C) 2017 Filipe Coelho <falktx@falktx.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. */
  18. #include "maths/MathsFunctions.h"
  19. #include "misc/Result.h"
  20. //==============================================================================
  21. namespace water
  22. {
  23. #ifdef CARLA_OS_WIN
  24. static inline
  25. Result getResultForLastError()
  26. {
  27. TCHAR messageBuffer [256] = { 0 };
  28. FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
  29. nullptr, GetLastError(), MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
  30. messageBuffer, (DWORD) numElementsInArray (messageBuffer) - 1, nullptr);
  31. return Result::fail (String (messageBuffer));
  32. }
  33. static inline
  34. int64 water_fileSetPosition (void* handle, int64 pos)
  35. {
  36. LARGE_INTEGER li;
  37. li.QuadPart = pos;
  38. li.LowPart = SetFilePointer ((HANDLE) handle, (LONG) li.LowPart, &li.HighPart, FILE_BEGIN); // (returns -1 if it fails)
  39. return li.QuadPart;
  40. }
  41. #else
  42. static inline
  43. Result getResultForErrno()
  44. {
  45. return Result::fail (String (strerror (errno)));
  46. }
  47. static inline
  48. int getFD (void* handle) noexcept { return (int) (pointer_sized_int) handle; }
  49. static inline
  50. void* fdToVoidPointer (int fd) noexcept { return (void*) (pointer_sized_int) fd; }
  51. static inline
  52. int64 water_fileSetPosition (void* handle, int64 pos)
  53. {
  54. if (handle != nullptr && lseek (getFD (handle), pos, SEEK_SET) == pos)
  55. return pos;
  56. return -1;
  57. }
  58. #endif
  59. }