all repos — mgba @ 8796f75fd3374c05d3452e284434c46eb9b178d4

mGBA Game Boy Advance Emulator

Windows: File handling fixes (fixes #1360)
Vicki Pfau vi@endrift.com
Fri, 22 Mar 2019 23:54:33 -0700
commit

8796f75fd3374c05d3452e284434c46eb9b178d4

parent

84a7b6a31690ff5a2b4edea9830807d23555aaaa

2 files changed, 10 insertions(+), 10 deletions(-)

jump to
M src/platform/windows/vfs-w32.csrc/platform/windows/vfs-w32.c

@@ -114,7 +114,7 @@ }

const char* dir = vdw->path; size_t size = sizeof(char) * (strlen(path) + strlen(dir) + 2); char* combined = malloc(size); - StringCbPrintf(combined, size, "%s\\%s", dir, path); + StringCbPrintfA(combined, size, "%s\\%s", dir, path); struct VFile* file = VFileOpen(combined, mode); free(combined);

@@ -129,7 +129,7 @@ }

const char* dir = vdw->path; size_t size = sizeof(char) * (strlen(path) + strlen(dir) + 2); char* combined = malloc(size); - StringCbPrintf(combined, size, "%s\\%s", dir, path); + StringCbPrintfA(combined, size, "%s\\%s", dir, path); struct VDir* vd2 = VDirOpen(combined); if (!vd2) {

@@ -144,14 +144,14 @@ struct VDirW32* vdw = (struct VDirW32*) vd;

if (!path) { return 0; } - const char* dir = vdw->path; - size_t size = sizeof(char) * (strlen(path) + strlen(dir) + 2); - char* combined = malloc(size); - StringCbPrintf(combined, size, "%s\\%s", dir, path); + wchar_t dir[MAX_PATH + 1]; + wchar_t pathw[MAX_PATH + 1]; + wchar_t combined[MAX_PATH + 1]; + MultiByteToWideChar(CP_UTF8, 0, vdw->path, -1, dir, MAX_PATH); + MultiByteToWideChar(CP_UTF8, 0, path, -1, pathw, MAX_PATH); + StringCchPrintfW(combined, MAX_PATH, L"%ws\\%ws", dir, pathw); - bool ret = DeleteFile(combined); - free(combined); - return ret; + return DeleteFileW(combined); } const char* _vdweName(struct VDirEntry* vde) {
M src/util/vfs/vfs-fd.csrc/util/vfs/vfs-fd.c

@@ -40,7 +40,7 @@ #ifdef _WIN32

flags |= O_BINARY; wchar_t wpath[PATH_MAX]; MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, sizeof(wpath) / sizeof(*wpath)); - int fd = _wopen(wpath, flags, 0666); + int fd = _wopen(wpath, flags, _S_IREAD | _S_IWRITE); #else int fd = open(path, flags, 0666); #endif