summaryrefslogtreecommitdiff
path: root/filesystem-win.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-06 17:36:07 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-06 17:36:07 -0500
commit132dcb648981050990e34a44925e6b54d0dc008c (patch)
tree7a41a97308b1921c62d2f5afd12c7cf475f14247 /filesystem-win.c
parent9e055b2e25455fc4fa0376495ccc9335059f3131 (diff)
more open menu, border thickness setting, fixed small text clipping issue
Diffstat (limited to 'filesystem-win.c')
-rw-r--r--filesystem-win.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/filesystem-win.c b/filesystem-win.c
new file mode 100644
index 0000000..4a66c09
--- /dev/null
+++ b/filesystem-win.c
@@ -0,0 +1,63 @@
+// see filesystem-posix.c for function documentation
+#include <sys/types.h>
+#include <sys/stat.h>
+
+static bool fs_file_exists(char const *path) {
+ struct _stat statbuf = {0};
+ if (_stat(path, &statbuf) != 0)
+ return false;
+ return statbuf.st_mode == _S_IFREG;
+}
+
+static char **fs_list_directory(char const *dirname) {
+ char file_pattern[256] = {0};
+ char **ret = NULL;
+ WIN32_FIND_DATA find_data;
+ HANDLE fhandle;
+ sprintf_s(file_pattern, sizeof file_pattern, "%s\\*", dirname);
+ fhandle = FindFirstFileA(file_pattern, &find_data);
+ if (fhandle != INVALID_HANDLE_VALUE) {
+ // first, figure out number of files
+ int nfiles = 1, idx = 0;
+ char **files;
+ while (FindNextFile(fhandle, &find_data)) {
+ if (!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
+ ++nfiles;
+ }
+ }
+ FindClose(fhandle);
+ // now, fill out files array
+ files = malloc((nfiles + 1) * sizeof *files);
+ if (files) {
+ fhandle = FindFirstFileA(file_pattern, &find_data);
+ if (fhandle != INVALID_HANDLE_VALUE) {
+ do {
+ if (!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
+ if (idx < nfiles) {
+ char *dup = _strdup(find_data.cFileName);
+ if (dup) {
+ files[idx++] = dup;
+ } else break; // stop now
+ }
+ }
+ } while (FindNextFile(fhandle, &find_data));
+ files[idx] = NULL;
+ FindClose(fhandle);
+ ret = files;
+ }
+ }
+ }
+ return ret;
+}
+
+static int fs_mkdir(char const *path) {
+ if (CreateDirectoryA(path, NULL)) {
+ // directory created successfully
+ return 1;
+ } else {
+ if (GetLastError() == ERROR_ALREADY_EXISTS) // directory already exists
+ return 0;
+ else
+ return -1; // some other error
+ }
+}