From a004e014e1315adf2296f2000798238bdfb58157 Mon Sep 17 00:00:00 2001 From: Lorenzo Cogotti Date: Fri, 15 Oct 2021 11:54:23 +0200 Subject: [PATCH] [lonetix/fs] Some fixes to Windows system specific API - implementation still partial --- lonetix/sys/fs_windows.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lonetix/sys/fs_windows.c b/lonetix/sys/fs_windows.c index 325c7ce..0136e69 100755 --- a/lonetix/sys/fs_windows.c +++ b/lonetix/sys/fs_windows.c @@ -30,7 +30,7 @@ static THREAD_LOCAL Pathbuf pathbuf; static wchar_t *Sys_Utf8PathToW(const char *path) { - int n = MultiByteToWideChar(CP_UTF8, 0, dir, -1, pathbuf.wstr, ARRAY_SIZE(pathbuf.wstr)); + int n = MultiByteToWideChar(CP_UTF8, 0, path, -1, pathbuf.wstr, ARRAY_SIZE(pathbuf.wstr)); if (n < 0) { Sys_SetErrStat(GetLastError(), "MultiByteToWideChar() failed"); return NULL; @@ -65,7 +65,7 @@ void Sys_Fclose(Fildes fd) CloseHandle(fd); } -typedef struct FileList dfFileList; +typedef struct FileList FileList; struct FileList { FileList *next; unsigned len; @@ -127,14 +127,15 @@ char **Sys_ListFiles(const char *dir, unsigned *nfiles, const char *pat) Sys_SetErrStat(errno, "_wfindfirst()/_wfindnext()"); goto fail; } - _findclose(findhn); char **files = (char **) malloc(sizeof(*files) * (count + 1) + nchars); if (!files) { Sys_OutOfMemory(); - return NULL; + goto fail; } + _findclose(findhn); // safe, can't fail anymore + char *namep = (char *) (files + count + 1); for (unsigned i = 0; i < count; i++) { files[i] = namep;