2 * Cross-platform C++ library for Carla, based on Juce v4
3 * Copyright (C) 2015 ROLI Ltd.
4 * Copyright (C) 2017-2023 Filipe Coelho <falktx@falktx.com>
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.
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.
16 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
21 #include "maths/MathsFunctions.h"
22 #include "misc/Result.h"
25 # include "text/String.h"
26 # import <Foundation/NSAutoreleasePool.h>
27 # import <Foundation/NSString.h>
32 #ifndef CARLA_PROPER_CPP11_SUPPORT
38 //==============================================================================
44 Result
getResultForLastError()
46 CHAR messageBuffer
[256] = { 0 };
48 FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
,
49 nullptr, GetLastError(), MAKELANGID (LANG_NEUTRAL
, SUBLANG_DEFAULT
),
50 messageBuffer
, (DWORD
) numElementsInArray (messageBuffer
) - 1, nullptr);
52 return Result::fail (messageBuffer
);
56 int64
water_fileSetPosition (void* handle
, int64 pos
)
60 li
.LowPart
= SetFilePointer ((HANDLE
) handle
, (LONG
) li
.LowPart
, &li
.HighPart
, FILE_BEGIN
); // (returns -1 if it fails)
64 HINSTANCE
getCurrentModuleInstanceHandle() noexcept
;
67 Result
getResultForErrno()
69 return Result::fail (std::strerror (errno
));
73 int getFD (void* handle
) noexcept
{ return (int) (pointer_sized_int
) handle
; }
76 void* fdToVoidPointer (int fd
) noexcept
{ return (void*) (pointer_sized_int
) fd
; }
79 int64
water_fileSetPosition (void* handle
, int64 pos
)
81 if (handle
!= nullptr && lseek (getFD (handle
), pos
, SEEK_SET
) == pos
)
90 String
nsStringToWater (NSString
* s
)
92 return CharPointer_UTF8 ([s UTF8String
]);
96 NSString
* waterStringToNS (const String
& s
)
98 return [NSString stringWithUTF8String
: s
.toUTF8()];
101 class AutoNSAutoreleasePool
{
103 AutoNSAutoreleasePool() : pool([NSAutoreleasePool
new]) {}
104 ~AutoNSAutoreleasePool() { [pool drain
]; }
107 NSAutoreleasePool
* const pool
;