mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
C: fix compilation on UWP
This commit is contained in:
parent
b72e4f01e2
commit
9e4c3010b0
|
@ -383,8 +383,12 @@ int32_t teavm_file_isDir(char16_t* name, int32_t nameSize) {
|
|||
|
||||
static int32_t teavm_file_checkExistingFileAccess(char16_t* name, int32_t nameSize, DWORD desiredAccess) {
|
||||
WCHAR* nativeName = teavm_file_convertPath(name, nameSize);
|
||||
#ifdef _WINDOWS_UWP
|
||||
HANDLE fileHandle = CreateFile2(nativeName, desiredAccess, FILE_SHARE_READ, OPEN_EXISTING, NULL);
|
||||
#else
|
||||
HANDLE fileHandle = CreateFileW(nativeName, desiredAccess, FILE_SHARE_READ, 0, OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL, 0);
|
||||
#endif
|
||||
int32_t result = fileHandle != INVALID_HANDLE_VALUE;
|
||||
if (fileHandle != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(fileHandle);
|
||||
|
@ -409,7 +413,11 @@ int32_t teavm_file_createDirectory(char16_t* name, int32_t nameSize) {
|
|||
|
||||
int32_t teavm_file_createFile(char16_t* name, int32_t nameSize) {
|
||||
WCHAR* nativeName = teavm_file_convertPath(name, nameSize);
|
||||
#ifdef _WINDOWS_UWP
|
||||
HANDLE fileHandle = CreateFile2(nativeName, GENERIC_WRITE, 0, OPEN_EXISTING, NULL);
|
||||
#else
|
||||
HANDLE fileHandle = CreateFileW(nativeName, GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
#endif
|
||||
int32_t result = 2;
|
||||
free(nativeName);
|
||||
|
||||
|
@ -436,7 +444,7 @@ int32_t teavm_file_delete(char16_t* name, int32_t nameSize) {
|
|||
int32_t teavm_file_rename(char16_t* name, int32_t nameSize, char16_t* newName, int32_t newNameSize) {
|
||||
WCHAR* nativeName = teavm_file_convertPath(name, nameSize);
|
||||
WCHAR* nativeNewName = teavm_file_convertPath(newName, newNameSize);
|
||||
int32_t result = MoveFileW(nativeName, nativeNewName);
|
||||
int32_t result = MoveFileExW(nativeName, nativeNewName, 0);
|
||||
free(nativeName);
|
||||
free(nativeNewName);
|
||||
return result;
|
||||
|
@ -462,7 +470,11 @@ int32_t teavm_file_setReadonly(char16_t* name, int32_t nameSize, int32_t readonl
|
|||
int64_t teavm_file_lastModified(char16_t* name, int32_t nameSize) {
|
||||
WCHAR* nativeName = teavm_file_convertPath(name, nameSize);
|
||||
FILETIME modified;
|
||||
#ifdef _WINDOWS_UWP
|
||||
HANDLE fileHandle = CreateFile2(nativeName, GENERIC_READ, 0, OPEN_EXISTING, NULL);
|
||||
#else
|
||||
HANDLE fileHandle = CreateFileW(nativeName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
#endif
|
||||
free(nativeName);
|
||||
if (fileHandle == INVALID_HANDLE_VALUE) {
|
||||
return 0;
|
||||
|
@ -481,7 +493,11 @@ int64_t teavm_file_lastModified(char16_t* name, int32_t nameSize) {
|
|||
int32_t teavm_file_setLastModified(char16_t* name, int32_t nameSize, int64_t lastModified) {
|
||||
WCHAR* nativeName = teavm_file_convertPath(name, nameSize);
|
||||
|
||||
#ifdef _WINDOWS_UWP
|
||||
HANDLE fileHandle = CreateFile2(nativeName, GENERIC_WRITE, 0, OPEN_EXISTING, NULL);
|
||||
#else
|
||||
HANDLE fileHandle = CreateFileW(nativeName, GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
#endif
|
||||
free(nativeName);
|
||||
if (fileHandle == INVALID_HANDLE_VALUE) {
|
||||
return 0;
|
||||
|
@ -514,7 +530,12 @@ int64_t teavm_file_open(char16_t* name, int32_t nameSize, int32_t mode) {
|
|||
DWORD desiredAccess = (readable ? GENERIC_READ : 0) | (writable ? GENERIC_WRITE : 0);
|
||||
|
||||
WCHAR* nativeName = teavm_file_convertPath(name, nameSize);
|
||||
HANDLE fileHandle = CreateFileW(nativeName, desiredAccess, 0, 0, creationDisposition, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
#ifdef _WINDOWS_UWP
|
||||
HANDLE fileHandle = CreateFile2(nativeName, desiredAccess, 0, creationDisposition, NULL);
|
||||
#else
|
||||
HANDLE fileHandle = CreateFileW(nativeName, desiredAccess, 0, 0, creationDisposition,
|
||||
FILE_ATTRIBUTE_NORMAL, 0);
|
||||
#endif
|
||||
free(nativeName);
|
||||
|
||||
if (fileHandle == INVALID_HANDLE_VALUE) {
|
||||
|
|
|
@ -147,6 +147,24 @@ int64_t teavm_currentTimeNano() {
|
|||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
static void* teavm_virtualAlloc(int size) {
|
||||
#ifdef _WINDOWS_UWP
|
||||
return VirtualAllocFromApp(
|
||||
NULL,
|
||||
size,
|
||||
MEM_RESERVE | MEM_COMMIT,
|
||||
PAGE_READWRITE
|
||||
);
|
||||
#else
|
||||
return VirtualAlloc(
|
||||
NULL,
|
||||
size,
|
||||
MEM_RESERVE | MEM_COMMIT,
|
||||
PAGE_READWRITE
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
void teavm_initHeap(int64_t heapSize) {
|
||||
long workSize = heapSize / 16;
|
||||
long regionsSize = (long) (heapSize / teavm_gc_regionSize);
|
||||
|
@ -158,24 +176,9 @@ void teavm_initHeap(int64_t heapSize) {
|
|||
int workPages = (int) ((workSize + pageSize + 1) / pageSize * pageSize);
|
||||
int regionsPages = (int) ((regionsSize * 2 + pageSize + 1) / pageSize * pageSize);
|
||||
|
||||
teavm_gc_heapAddress = VirtualAlloc(
|
||||
NULL,
|
||||
heapPages,
|
||||
MEM_RESERVE | MEM_COMMIT,
|
||||
PAGE_READWRITE
|
||||
);
|
||||
teavm_gc_gcStorageAddress = VirtualAlloc(
|
||||
NULL,
|
||||
workPages,
|
||||
MEM_RESERVE | MEM_COMMIT,
|
||||
PAGE_READWRITE
|
||||
);
|
||||
teavm_gc_regionsAddress = VirtualAlloc(
|
||||
NULL,
|
||||
regionsPages,
|
||||
MEM_RESERVE | MEM_COMMIT,
|
||||
PAGE_READWRITE
|
||||
);
|
||||
teavm_gc_heapAddress = teavm_virtualAlloc(heapPages);
|
||||
teavm_gc_gcStorageAddress = teavm_virtualAlloc(workPages);
|
||||
teavm_gc_regionsAddress = teavm_virtualAlloc(regionsPages);
|
||||
|
||||
teavm_gc_gcStorageSize = (int) workSize;
|
||||
teavm_gc_regionMaxCount = regionsSize;
|
||||
|
@ -202,10 +205,17 @@ int64_t teavm_currentTimeNano() {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define gmtime_r(a, b) gmtime_s(b, a)
|
||||
#define mktime_r(a, b) mktime_s(b, a)
|
||||
#define localtime_r(a, b) localtime_s(b, a)
|
||||
#endif
|
||||
|
||||
int32_t teavm_timeZoneOffset() {
|
||||
struct tm tm;
|
||||
time_t t = time(NULL);
|
||||
time_t local = mktime(localtime(&t));
|
||||
time_t utc = mktime(gmtime(&t));
|
||||
time_t local = mktime(localtime_r(&t, &tm));
|
||||
time_t utc = mktime(gmtime_r(&t, &tm));
|
||||
return difftime(utc, local) / 60;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,13 @@
|
|||
#ifdef _MSC_VER
|
||||
#define alignas(n) __declspec(align(n))
|
||||
#pragma comment (lib,"uuid.lib")
|
||||
|
||||
#ifdef WINAPI_FAMILY
|
||||
#if WINAPI_FAMILY == 2 || WINAPI_FAMILY == 3 || WINAPI_FAMILY == 5
|
||||
#define _WINDOWS_UWP 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct TeaVM_Object {
|
||||
|
|
Loading…
Reference in New Issue
Block a user