Kaynağa Gözat

feat: add win32 apis for File Operations

Douglas Andreani 1 yıl önce
ebeveyn
işleme
3ffe9befaa
1 değiştirilmiş dosya ile 19 ekleme ve 5 silme
  1. 19 5
      src/platform.h

+ 19 - 5
src/platform.h

@@ -1,19 +1,25 @@
 #include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+
 #ifdef _WIN32
 #include <io.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/types.h>
 #else 
-#include <sys/stat.h>
 #include <unistd.h>
 #include <sys/types.h>
-#include <string.h>
 #endif
 
 #define STAT(path, buf) platform_stat(path, buf)
-static int platform_stat(const char *path, struct stat *buf)
+static int platform_stat(const char *path, void *buf)
 {
   #ifdef _WIN32
-    return _stat(path, buf);
+    struct _stat *bufstat = (struct _stat*) buf;
+    return _stat(path, bufstat);
   #else 
+    struct stat *bufstat = (struct stat*) buf;
     return stat(path, buf);
   #endif
 }
@@ -23,8 +29,13 @@ static int platform_stat(const char *path, struct stat *buf)
 static FILE* platform_fopen(const char* path, const char* method)
 {
   #ifdef _WIN32
+    FILE* fp;
+    errno_t err;
+    err = fopen_s(&fp, path, method);
+    if (err != 0) {
+      return NULL;
+    }
   #else
-
     FILE* fp = fopen(path, method);
   #endif
 
@@ -35,6 +46,7 @@ static FILE* platform_fopen(const char* path, const char* method)
 static int platform_access(const char* path, int mode)
 {
   #ifdef _WIN32
+    return _access(path, mode);
   #else 
     return access(path, mode);
   #endif
@@ -44,6 +56,8 @@ static int platform_access(const char* path, int mode)
 static char *platform_strcpy(char* dst, char* src)
 {
   #ifdef _WIN32
+    strcpy_s(dst, 1024, src);
+    return NULL;
   #else 
     return strcpy(dst, src);
   #endif