Skip to content

Commit 6772c65

Browse files
committed
xrCore: now build on Linux
1 parent 253aca9 commit 6772c65

File tree

10 files changed

+229
-9
lines changed

10 files changed

+229
-9
lines changed

src/xrCore/FS.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ CVirtualFileRW::CVirtualFileRW(const char* cFileName)
520520
::fstat(hSrcFile, &file_info);
521521
Size = (int)file_info.st_size;
522522
R_ASSERT3(Size, cFileName, xrDebug::ErrorToString(GetLastError()));
523-
data = (char*)::mmap(NULL, 0, PROT_READ | PROT_WRITE, MAP_SHARED, hSrcFile, 0);
523+
data = (char*)::mmap(NULL, Size, PROT_READ | PROT_WRITE, MAP_SHARED, hSrcFile, 0);
524524
#endif
525525
#ifdef FS_DEBUG
526526
register_file_mapping(data, Size, cFileName);
@@ -563,7 +563,7 @@ CVirtualFileReader::CVirtualFileReader(const char* cFileName)
563563
::fstat(hSrcFile, &file_info);
564564
Size = (int)file_info.st_size;
565565
R_ASSERT3(Size, cFileName, xrDebug::ErrorToString(GetLastError()));
566-
data = (char*)::mmap(NULL, 0, PROT_READ, MAP_SHARED, hSrcFile, 0);
566+
data = (char*)::mmap(NULL, Size, PROT_READ, MAP_SHARED, hSrcFile, 0);
567567
#endif
568568
R_ASSERT3(data, cFileName, xrDebug::ErrorToString(GetLastError()));
569569

src/xrCore/FileSystem_borland.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
//----------------------------------------------------
22
// file: FileSystem.cpp
33
//----------------------------------------------------
4-
#if defined(WINDOWS)
54
#include "stdafx.h"
65
#pragma hdrstop
76

87
#include "FileSystem.h"
9-
8+
#ifdef WINDOWS
109
#include <io.h>
1110
#include <fcntl.h>
1211
#include <sys\stat.h>

src/xrCore/PostProcess/PPInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "StdAfx.h"
1+
#include "stdafx.h"
22
#include "PPInfo.hpp"
33

44
SPPInfo& SPPInfo::add(const SPPInfo& ppi)

src/xrCore/PostProcess/PostProcess.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "StdAfx.h"
1+
#include "stdafx.h"
22
#include "PostProcess.hpp"
33

44
// postprocess value LOAD method implementation

src/xrCore/Threading/Event.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "stdafx.h"
22
#include "Event.hpp"
3+
#if defined(WINDOWS)
4+
#include <windows.h>
35

46
Event::Event() noexcept { handle = (void*)CreateEvent(NULL, FALSE, FALSE, NULL); }
57
Event::~Event() noexcept { CloseHandle(handle); }
@@ -10,3 +12,15 @@ bool Event::Wait(u32 millisecondsTimeout) const noexcept
1012
{
1113
return WaitForSingleObject(handle, millisecondsTimeout) != WAIT_TIMEOUT;
1214
}
15+
#elif defined(LINUX)
16+
Event::Event() noexcept { handle = (void*)malloc(1); }
17+
Event::~Event() noexcept { free(handle); }
18+
void Event::Reset() noexcept { memset(handle, 1, 1); }
19+
void Event::Set() noexcept { memset(handle, 0, 1); }
20+
void Event::Wait() const noexcept { Sleep(0); }
21+
bool Event::Wait(u32 millisecondsTimeout) const noexcept
22+
{
23+
Sleep(millisecondsTimeout);
24+
return true;
25+
}
26+
#endif

src/xrCore/_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ using string4096 = char[4096];
7070
using string_path = char[2 * max_path];
7171

7272
// XXX: Replace __interface with either struct or class. MS defines it as struct for COM, but this project is C++.
73+
#if defined(WINDOWS)
7374
#define xr_pure_interface __interface
74-
75+
#endif
7576
#endif

src/xrCore/stream_reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void CStreamReader::map(const u32& new_offset)
4444
(u8*)MapViewOfFile(m_file_mapping_handle, FILE_MAP_READ, 0, start_offset, m_current_window_size);
4545
#elif defined(LINUX)
4646
m_current_map_view_of_file =
47-
(u8*)mmap(NULL, m_current_window_size, PROT_READ, MAP_SHARED, m_file_mapping_handle, start_offset); // TODO проверить не могу до полной сборки под Linux
47+
(u8*)::mmap(NULL, m_current_window_size, PROT_READ, MAP_SHARED, m_file_mapping_handle, start_offset); // TODO проверить не могу до полной сборки под Linux
4848
#endif
4949
m_current_pointer = m_current_map_view_of_file;
5050

src/xrCore/stream_reader_inline.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#ifndef STREAM_READER_INLINE_H
22
#define STREAM_READER_INLINE_H
3+
#ifdef LINUX
4+
#include <sys/mman.h>
5+
#endif
36

47
IC CStreamReader::CStreamReader() {}
58
IC CStreamReader::CStreamReader(const CStreamReader& object)
@@ -19,7 +22,7 @@ IC const HANDLE& CStreamReader::file_mapping_handle() const { return (m_file_map
1922
#if defined(WINDOWS)
2023
IC void CStreamReader::unmap() { UnmapViewOfFile(m_current_map_view_of_file); }
2124
#else
22-
IC void CStreamReader::unmap() { ; }
25+
IC void CStreamReader::unmap() { ::munmap(const_cast<u8*>(m_current_map_view_of_file), m_current_window_size); }
2326
#endif
2427
IC void CStreamReader::remap(const u32& new_offset)
2528
{

src/xrCore/xrMemory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
Поэтому всё-же стоит переопределять для большинства случаев операторы new и delete.
1212
А для остального мы будем полагать (и надеяться), что прокси справится без проблем.
1313
*/
14+
#if defined(WINDOWS) // Не знаю, как это на виндах работает, но на линуксе ломается линковка из-за множественного объявления __TBB_malloc_proxy_helper_object
1415
#include "tbb/tbbmalloc_proxy.h"
16+
#endif
1517

1618
class XRCORE_API xrMemory
1719
{

src/xrCore/xr_ini.cpp

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,207 @@
66
XRCORE_API CInifile const* pSettings = nullptr;
77
XRCORE_API CInifile const* pSettingsAuth = nullptr;
88

9+
#if defined(LINUX)
10+
#include <stdint.h>
11+
#define MSVCRT_EINVAL 22
12+
#define MSVCRT_ERANGE 34
13+
14+
#define MSVCRT_UI64_MAX (((uint64_t)0xffffffff << 32) | 0xffffffff)
15+
16+
/**
17+
* from wine@dlls/msvcrt/string.c
18+
*
19+
* @param fileName
20+
* @param readOnly
21+
* @return
22+
*/
23+
int _cdecl _i64toa_s(int64_t value, char *str, size_t size, int radix){
24+
uint64_t val;
25+
unsigned int digit;
26+
int is_negative;
27+
char buffer[65], *pos;
28+
size_t len;
29+
30+
if (!(str != NULL))
31+
return MSVCRT_EINVAL;
32+
if (!(size > 0))
33+
return MSVCRT_EINVAL;
34+
if (!(radix >= 2 && radix <= 36)) {
35+
str[0] = '\0';
36+
return MSVCRT_EINVAL;
37+
}
38+
39+
if (value < 0 && radix == 10) {
40+
is_negative = 1;
41+
val = -value;
42+
} else {
43+
is_negative = 0;
44+
val = value;
45+
}
46+
47+
pos = buffer + 64;
48+
*pos = '\0';
49+
50+
do {
51+
digit = val % radix;
52+
val /= radix;
53+
54+
if (digit < 10)
55+
*--pos = '0' + digit;
56+
else
57+
*--pos = 'a' + digit - 10;
58+
} while (val != 0);
59+
60+
if (is_negative)
61+
*--pos = '-';
62+
63+
len = buffer + 65 - pos;
64+
if (len > size) {
65+
size_t i;
66+
char *p = str;
67+
68+
/* Copy the temporary buffer backwards up to the available number of
69+
* characters. Don't copy the negative sign if present. */
70+
71+
if (is_negative) {
72+
p++;
73+
size--;
74+
}
75+
76+
for (pos = buffer + 63, i = 0; i < size; i++)
77+
*p++ = *pos--;
78+
79+
str[0] = '\0';
80+
return MSVCRT_ERANGE;
81+
}
82+
83+
memcpy(str, pos, len);
84+
return 0;
85+
}
86+
87+
int _cdecl _ui64toa_s(uint64_t value, char *str, size_t size, int radix) {
88+
char buffer[65], *pos;
89+
int digit;
90+
91+
if (!(str != NULL))
92+
return MSVCRT_EINVAL;
93+
if (!(size > 0))
94+
return MSVCRT_EINVAL;
95+
if (!(radix >= 2 && radix <= 36)) {
96+
str[0] = '\0';
97+
return MSVCRT_EINVAL;
98+
}
99+
100+
pos = buffer + 64;
101+
*pos = '\0';
102+
103+
do {
104+
digit = value % radix;
105+
value /= radix;
106+
107+
if (digit < 10)
108+
*--pos = '0' + digit;
109+
else
110+
*--pos = 'a' + digit - 10;
111+
} while (value != 0);
112+
113+
if (buffer - pos + 65 > size) {
114+
return MSVCRT_EINVAL;
115+
}
116+
117+
memcpy(str, pos, buffer - pos + 65);
118+
return 0;
119+
}
120+
121+
LARGE_INTEGER _cdecl _atoi64( const char *str )
122+
{
123+
ULARGE_INTEGER RunningTotal = 0;
124+
char bMinus = 0;
125+
126+
while (*str == ' ' || (*str >= '\011' && *str <= '\015')) {
127+
str++;
128+
} /* while */
129+
130+
if (*str == '+') {
131+
str++;
132+
} else if (*str == '-') {
133+
bMinus = 1;
134+
str++;
135+
} /* if */
136+
137+
while (*str >= '0' && *str <= '9') {
138+
RunningTotal = RunningTotal * 10 + *str - '0';
139+
str++;
140+
} /* while */
141+
142+
return bMinus ? -RunningTotal : RunningTotal;
143+
}
144+
145+
uint64_t _cdecl _strtoui64_l(const char *nptr, char **endptr, int base, locale_t locale)
146+
{
147+
BOOL negative = FALSE;
148+
uint64_t ret = 0;
149+
150+
151+
if (!(nptr != NULL)) return 0;
152+
if (!(base == 0 || base >= 2)) return 0;
153+
if (!(base <= 36)) return 0;
154+
155+
while(isspace(*nptr)) nptr++;
156+
157+
if(*nptr == '-') {
158+
negative = TRUE;
159+
nptr++;
160+
} else if(*nptr == '+')
161+
nptr++;
162+
163+
if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') {
164+
base = 16;
165+
nptr += 2;
166+
}
167+
168+
if(base == 0) {
169+
if(*nptr=='0')
170+
base = 8;
171+
else
172+
base = 10;
173+
}
174+
175+
while(*nptr) {
176+
char cur = tolower(*nptr);
177+
int v;
178+
179+
if(isdigit(cur)) {
180+
if(cur >= '0'+base)
181+
break;
182+
v = *nptr-'0';
183+
} else {
184+
if(cur<'a' || cur>='a'+base-10)
185+
break;
186+
v = cur-'a'+10;
187+
}
188+
189+
nptr++;
190+
191+
if(ret>MSVCRT_UI64_MAX/base || ret*base>MSVCRT_UI64_MAX-v) {
192+
ret = MSVCRT_UI64_MAX;
193+
} else
194+
ret = ret*base + v;
195+
}
196+
197+
if(endptr)
198+
*endptr = (char*)nptr;
199+
200+
return negative ? -ret : ret;
201+
}
202+
203+
uint64_t _cdecl _strtoui64(const char *nptr, char **endptr, int base)
204+
{
205+
return _strtoui64_l(nptr, endptr, base, NULL);
206+
}
207+
#endif
208+
209+
9210
CInifile* CInifile::Create(pcstr fileName, bool readOnly)
10211
{
11212
return new CInifile(fileName, readOnly);

0 commit comments

Comments
 (0)