Skip to content

Commit

Permalink
Add compat_access (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbatalov committed Apr 26, 2023
1 parent aa99b2e commit a881522
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
#include <stdio.h>
#include <string.h>

#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h> // access
#endif

#include "actions.h"
#include "animation.h"
#include "art.h"
Expand Down Expand Up @@ -1336,12 +1330,12 @@ static int gameDbInit()
for (patch_index = 0; patch_index < 1000; patch_index++) {
snprintf(filename, sizeof(filename), "patch%03d.dat", patch_index);

if (access(filename, 0) == 0) {
if (compat_access(filename, 0) == 0) {
dbOpen(filename, 0, NULL, 1);
}
}

if (access("f2_res.dat", 0) == 0) {
if (compat_access("f2_res.dat", 0) == 0) {
dbOpen("f2_res.dat", 0, NULL, 1);
}

Expand Down
9 changes: 9 additions & 0 deletions src/platform_compat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ void compat_resolve_path(char* path)
#endif
}

int compat_access(const char* path, int mode)
{
char nativePath[COMPAT_MAX_PATH];
strcpy(nativePath, path);
compat_windows_path_to_native(nativePath);
compat_resolve_path(nativePath);
return access(nativePath, mode);
}

char* compat_strdup(const char* string)
{
return SDL_strdup(string);
Expand Down
1 change: 1 addition & 0 deletions src/platform_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ int compat_remove(const char* path);
int compat_rename(const char* oldFileName, const char* newFileName);
void compat_windows_path_to_native(char* path);
void compat_resolve_path(char* path);
int compat_access(const char* path, int mode);
char* compat_strdup(const char* string);
long getFileSize(FILE* stream);

Expand Down

0 comments on commit a881522

Please sign in to comment.