Skip to content

Commit 30f6a64

Browse files
committed
Fix CrossPlatform for non Windows platforms
CrossPlatform.cpp contained a number of compile errors and a bug in getDataFile() for non Windows platforms.
1 parent 45f7f32 commit 30f6a64

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

‎src/Engine/CrossPlatform.cpp‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#pragma comment(lib, "shell32.lib")
3434
#pragma comment(lib, "shlwapi.lib")
3535
#else
36+
#include <string.h>
3637
#include <stdio.h>
3738
#include <stdlib.h>
3839
#include <sys/param.h>
@@ -63,7 +64,7 @@ std::string getDataFile(const std::string &filename)
6364

6465
// Try lowercase and uppercase names
6566
struct stat info;
66-
if (stat(newName.c_str(), &info) == 0)
67+
if (stat(newPath.c_str(), &info) == 0)
6768
{
6869
return newPath;
6970
}
@@ -159,20 +160,22 @@ std::wstring findDataFolder()
159160
}
160161
}
161162
#else
162-
char path[MAXPATHLEN];
163+
wchar_t path[MAXPATHLEN];
163164
struct stat info;
164165

165166
// Check shared directory
166-
path = "/usr/share/openxcom/"
167-
if (stat(path, &info) == 0 && S_ISDIR(info.st_mode))
167+
const char* shared = "/usr/share/openxcom/";
168+
if (stat(shared, &info) == 0 && S_ISDIR(info.st_mode))
168169
{
170+
mbstowcs(path, shared, strlen(shared)+1);
169171
return path;
170172
}
171173

172174
// Check working directory
173-
path = "./DATA/";
174-
if (stat(path, &info) == 0 && S_ISDIR(info.st_mode))
175+
const char* working = "./DATA/";
176+
if (stat(working, &info) == 0 && S_ISDIR(info.st_mode))
175177
{
178+
mbstowcs(path, working, strlen(working)+1);
176179
return path;
177180
}
178181
#endif
@@ -220,24 +223,27 @@ std::wstring findUserFolder()
220223
}
221224
}
222225
#else
223-
char path[MAXPATHLEN];
226+
wchar_t path[MAXPATHLEN];
224227
struct stat info;
225-
228+
226229
// Check HOME directory
227230
char *homedir = getenv("HOME");
228231
if (homedir)
229232
{
230-
snprintf(path, MAXPATHLEN, "%s/.openxcom/", homedir);
231-
if (stat(path, &info) == 0 && S_ISDIR(info.st_mode))
233+
char homePath[MAXPATHLEN];
234+
snprintf(homePath, MAXPATHLEN, "%s/.openxcom/", homedir);
235+
if (stat(homePath, &info) == 0 && S_ISDIR(info.st_mode))
232236
{
237+
mbstowcs(path, homePath, strlen(homePath)+1);
233238
return path;
234239
}
235240
}
236241

237242
// Check working directory
238-
path = "./USER/";
239-
if (stat(path, &info) == 0 && S_ISDIR(info.st_mode))
243+
const char* working = "./USER/";
244+
if (stat(working, &info) == 0 && S_ISDIR(info.st_mode))
240245
{
246+
mbstowcs(path, working, strlen(working)+1);
241247
return path;
242248
}
243249
#endif

0 commit comments

Comments
 (0)