summaryrefslogtreecommitdiff
path: root/filesystem-win.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-04-16 18:36:47 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2021-04-16 18:36:47 -0400
commited3adc7e99c23d5f12b36ab162b5c8489f25a2d8 (patch)
treefda8d02223314dbfcb64e60a3cbbb64eb890b410 /filesystem-win.c
parent4666383f063ca56ba0ef1e5b42003b3096f443b1 (diff)
fix windows build
Diffstat (limited to 'filesystem-win.c')
-rw-r--r--filesystem-win.c24
1 files 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 <sys/stat.h>
#include <io.h>
-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