From ed3adc7e99c23d5f12b36ab162b5c8489f25a2d8 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Fri, 16 Apr 2021 18:36:47 -0400 Subject: fix windows build --- filesystem-win.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/filesystem-win.c b/filesystem-win.c index d0aef37..a16dc6b 100644 --- a/filesystem-win.c +++ b/filesystem-win.c @@ -3,15 +3,17 @@ #include #include -FsType fs_path_type(char const *path) { - struct _stat statbuf = {0}; - if (_stat(path, &statbuf) != 0) +static FsType windows_file_attributes_to_type(DWORD attrs) { + if (attrs == INVALID_FILE_ATTRIBUTES) return FS_NON_EXISTENT; - if (statbuf.st_mode & _S_IFREG) - return FS_FILE; - if (statbuf.st_mode & _S_IFDIR) + else if (attrs & FILE_ATTRIBUTE_DIRECTORY) return FS_DIRECTORY; - return FS_OTHER; + else + return FS_FILE; +} + +FsType fs_path_type(char const *path) { + return windows_file_attributes_to_type(GetFileAttributesA(path)); } FsPermission fs_path_permission(char const *path) { @@ -37,7 +39,6 @@ FsDirectoryEntry **fs_list_directory(char const *dirname) { if (fhandle != INVALID_HANDLE_VALUE) { // first, figure out number of files int nfiles = 1, idx = 0; - char **files; while (FindNextFile(fhandle, &find_data)) { ++nfiles; } @@ -54,12 +55,7 @@ FsDirectoryEntry **fs_list_directory(char const *dirname) { FsDirectoryEntry *entry = calloc(1, sizeof *entry + len + 1); if (entry) { DWORD attrs = find_data.dwFileAttributes; - if (attrs & FILE_ATTRIBUTE_NORMAL) - entry->type = FS_FILE; - else if (attrs & FILE_ATTRIBUTE_DIRECTORY) - entry->type = FS_DIRECTORY; - else - entry->type = FS_OTHER; + entry->type = windows_file_attributes_to_type(attrs); memcpy(entry->name, filename, len); files[idx++] = entry; } else break; // stop now -- cgit v1.2.3