From 18306622fc4350d96543673b702b9f0e59aae45d Mon Sep 17 00:00:00 2001
From: Mitya Selivanov <automainint@guattari.tech>
Date: Fri, 15 Sep 2023 22:27:36 +0200
Subject: win32: fix

---
 source/kit/file.c | 55 ++++++++++++++++---------------------------------------
 1 file changed, 16 insertions(+), 39 deletions(-)

(limited to 'source')

diff --git a/source/kit/file.c b/source/kit/file.c
index 4d6b979..faeebcf 100644
--- a/source/kit/file.c
+++ b/source/kit/file.c
@@ -228,29 +228,7 @@ kit_str_t kit_path_take(kit_str_t path, i64 count) {
   return s;
 }
 
-#if defined(_WIN32) && !defined(__CYGWIN__)
-static void kit_win32_prepare_path_(WCHAR *buf, kit_str_t path) {
-  assert(path.size == 0 || path.values != NULL);
-  assert(path.size + 5 < PATH_BUF_SIZE);
-
-  memset(buf, 0, PATH_BUF_SIZE);
-  buf[0] = L'\\';
-  buf[1] = L'\\';
-  buf[2] = L'?';
-  buf[3] = L'\\';
-  if (path.size > 0 && path.size + 5 < PATH_BUF_SIZE)
-    for (i64 i = 0; i < path.size; i++) {
-      if (path.values[i] == '/')
-        buf[4 + i] = L'\\';
-      else
-        buf[4 + i] = path.values[i];
-    }
-}
-#  define PREPARE_PATH_BUF_   \
-    WCHAR buf[PATH_BUF_SIZE]; \
-    kit_win32_prepare_path_(buf, path)
-#else
-static void kit_unix_prepare_path_(char *buf, kit_str_t path) {
+static void kit_prepare_path_(char *buf, kit_str_t path) {
   assert(path.size == 0 || path.values != NULL);
   assert(path.size + 1 < PATH_BUF_SIZE);
 
@@ -258,15 +236,14 @@ static void kit_unix_prepare_path_(char *buf, kit_str_t path) {
   if (path.size > 0 && path.size + 1 < PATH_BUF_SIZE)
     memcpy(buf, path.values, path.size);
 }
-#  define PREPARE_PATH_BUF_  \
-    char buf[PATH_BUF_SIZE]; \
-    kit_unix_prepare_path_(buf, path)
-#endif
+#define PREPARE_PATH_BUF_  \
+  char buf[PATH_BUF_SIZE]; \
+  kit_prepare_path_(buf, path)
 
 kit_status_t kit_folder_create(kit_str_t path) {
   PREPARE_PATH_BUF_;
 #if defined(_WIN32) && !defined(__CYGWIN__)
-  return CreateDirectoryW(buf, NULL) ? KIT_OK
+  return CreateDirectoryA(buf, NULL) ? KIT_OK
                                      : KIT_ERROR_MKDIR_FAILED;
 #else
   return mkdir(buf, 0775) == 0 ? KIT_OK : KIT_ERROR_MKDIR_FAILED;
@@ -296,7 +273,7 @@ kit_status_t kit_folder_create_recursive(kit_str_t path) {
 kit_status_t kit_file_remove(kit_str_t path) {
   PREPARE_PATH_BUF_;
 #if defined(_WIN32) && !defined(__CYGWIN__)
-  return DeleteFileW(buf) ? KIT_OK : KIT_ERROR_UNLINK_FAILED;
+  return DeleteFileA(buf) ? KIT_OK : KIT_ERROR_UNLINK_FAILED;
 #else
   return unlink(buf) == 0 ? KIT_OK : KIT_ERROR_UNLINK_FAILED;
 #endif
@@ -305,7 +282,7 @@ kit_status_t kit_file_remove(kit_str_t path) {
 kit_status_t kit_folder_remove(kit_str_t path) {
   PREPARE_PATH_BUF_;
 #if defined(_WIN32) && !defined(__CYGWIN__)
-  return RemoveDirectoryW(buf) ? KIT_OK : KIT_ERROR_RMDIR_FAILED;
+  return RemoveDirectoryA(buf) ? KIT_OK : KIT_ERROR_RMDIR_FAILED;
 #else
   return rmdir(buf) == 0 ? KIT_OK : KIT_ERROR_RMDIR_FAILED;
 #endif
@@ -357,8 +334,8 @@ kit_status_t kit_file_remove_recursive(kit_str_t        path,
 kit_path_type_t kit_path_type(kit_str_t path) {
   PREPARE_PATH_BUF_;
 #if defined(_WIN32) && !defined(__CYGWIN__)
-  if (PathFileExistsW(buf)) {
-    if ((GetFileAttributesW(buf) & FILE_ATTRIBUTE_DIRECTORY) != 0)
+  if (PathFileExistsA(buf)) {
+    if ((GetFileAttributesA(buf) & FILE_ATTRIBUTE_DIRECTORY) != 0)
       return KIT_PATH_FOLDER;
     else
       return KIT_PATH_FILE;
@@ -382,7 +359,7 @@ kit_file_info_t kit_file_info(kit_str_t path) {
   PREPARE_PATH_BUF_;
 
 #if defined(_WIN32) && !defined(__CYGWIN__)
-  HANDLE f = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ, NULL,
+  HANDLE f = CreateFileA(buf, GENERIC_READ, FILE_SHARE_READ, NULL,
                          OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
   if (f != INVALID_HANDLE_VALUE) {
     FILETIME ft;
@@ -416,7 +393,7 @@ kit_file_info_t kit_file_info(kit_str_t path) {
     result.time_modified_sec  = (i64) info.st_mtim.tv_sec;
     result.time_modified_nsec = (i32) info.st_mtim.tv_nsec;
 #  endif
-    result.status = KIT_OK;
+    result.status            = KIT_OK;
     return result;
   }
 #endif
@@ -442,7 +419,7 @@ kit_path_list_t kit_folder_enum(kit_str_t        path,
   buf[path.size + 5] = '*';
 
   WIN32_FIND_DATAW data;
-  HANDLE           find = FindFirstFileW(buf, &data);
+  HANDLE           find = FindFirstFileA(buf, &data);
 
   if (find == INVALID_HANDLE_VALUE)
     return result;
@@ -466,7 +443,7 @@ kit_path_list_t kit_folder_enum(kit_str_t        path,
 
     for (i64 i = 0; i < size; i++)
       result.files.values[n].values[i] = data.cFileName[i];
-  } while (FindNextFileW(find, &data) != 0);
+  } while (FindNextFileA(find, &data) != 0);
 
   FindClose(find);
 #else
@@ -637,9 +614,9 @@ kit_mapped_file_t kit_file_map(kit_str_t path, i64 size, i32 mode) {
   }
 
   mf.status = KIT_OK;
-  mf.size = size;
-  mf.bytes = (u8 *) p;
-  mf._fd = fd;
+  mf.size   = size;
+  mf.bytes  = (u8 *) p;
+  mf._fd    = fd;
 #endif
 
   return mf;
-- 
cgit v1.2.3