Windows: File handling fixes (fixes #1360)

This commit is contained in:
Vicki Pfau 2019-03-22 23:54:33 -07:00
parent 84a7b6a316
commit 8796f75fd3
2 changed files with 10 additions and 10 deletions

View File

@ -114,7 +114,7 @@ struct VFile* _vdwOpenFile(struct VDir* vd, const char* path, int mode) {
const char* dir = vdw->path; const char* dir = vdw->path;
size_t size = sizeof(char) * (strlen(path) + strlen(dir) + 2); size_t size = sizeof(char) * (strlen(path) + strlen(dir) + 2);
char* combined = malloc(size); char* combined = malloc(size);
StringCbPrintf(combined, size, "%s\\%s", dir, path); StringCbPrintfA(combined, size, "%s\\%s", dir, path);
struct VFile* file = VFileOpen(combined, mode); struct VFile* file = VFileOpen(combined, mode);
free(combined); free(combined);
@ -129,7 +129,7 @@ struct VDir* _vdwOpenDir(struct VDir* vd, const char* path) {
const char* dir = vdw->path; const char* dir = vdw->path;
size_t size = sizeof(char) * (strlen(path) + strlen(dir) + 2); size_t size = sizeof(char) * (strlen(path) + strlen(dir) + 2);
char* combined = malloc(size); char* combined = malloc(size);
StringCbPrintf(combined, size, "%s\\%s", dir, path); StringCbPrintfA(combined, size, "%s\\%s", dir, path);
struct VDir* vd2 = VDirOpen(combined); struct VDir* vd2 = VDirOpen(combined);
if (!vd2) { if (!vd2) {
@ -144,14 +144,14 @@ bool _vdwDeleteFile(struct VDir* vd, const char* path) {
if (!path) { if (!path) {
return 0; return 0;
} }
const char* dir = vdw->path; wchar_t dir[MAX_PATH + 1];
size_t size = sizeof(char) * (strlen(path) + strlen(dir) + 2); wchar_t pathw[MAX_PATH + 1];
char* combined = malloc(size); wchar_t combined[MAX_PATH + 1];
StringCbPrintf(combined, size, "%s\\%s", dir, path); 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); return DeleteFileW(combined);
free(combined);
return ret;
} }
const char* _vdweName(struct VDirEntry* vde) { const char* _vdweName(struct VDirEntry* vde) {

View File

@ -40,7 +40,7 @@ struct VFile* VFileOpenFD(const char* path, int flags) {
flags |= O_BINARY; flags |= O_BINARY;
wchar_t wpath[PATH_MAX]; wchar_t wpath[PATH_MAX];
MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, sizeof(wpath) / sizeof(*wpath)); 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 #else
int fd = open(path, flags, 0666); int fd = open(path, flags, 0666);
#endif #endif