]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Add back the correct directory handling for msvc
authorDale Weiler <killfieldengine@gmail.com>
Fri, 11 Oct 2013 09:09:55 +0000 (05:09 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Fri, 11 Oct 2013 09:09:55 +0000 (05:09 -0400)
Makefile
msvc.c
platform.h

index 0b57b9c01a23c7c2f701a49747f99178f87cd935..bfc68c72cb8f38a9c381d6ce2f2f79fcf0065309 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -149,8 +149,8 @@ install-doc:
 # DO NOT DELETE
 
 pak.o: gmqcc.h opts.def platform.h
-ansi.o: platform.h
-util.o: gmqcc.h opts.def
+ansi.o: platform.h gmqcc.h opts.def
+util.o: gmqcc.h opts.def platform.h
 stat.o: gmqcc.h opts.def
 fs.o: gmqcc.h opts.def platform.h
 conout.o: gmqcc.h opts.def platform.h
diff --git a/msvc.c b/msvc.c
index 2c6a3ed6656d28bc5d81f1983a2c00e1e6c91f85..3f447970b07e20388f6b353782a3d43b6741d8d1 100644 (file)
--- a/msvc.c
+++ b/msvc.c
@@ -22,7 +22,6 @@
  */
 #include <string.h>
 #include <stdlib.h>
-#include <io.h>
 
 #include "platform.h"
 
@@ -191,15 +190,57 @@ int platform_mkdir(const char *path, int mode) {
 }
 
 DIR *platform_opendir(const char *path) {
-    return opendir(path);
+    DIR *dir = (DIR*)mem_a(sizeof(DIR) + strlen(path));
+    if (!dir)
+        return NULL;
+
+    platform_strncpy(dir->dd_name, path, strlen(path));
+    return dir;
 }
 
 int platform_closedir(DIR *dir) {
-    return closedir(dir);
+    FindClose((HANDLE)dir->dd_handle);
+    mem_d((void*)dir);
+    return 0;
 }
 
 struct dirent *platform_readdir(DIR *dir) {
-    return readdir(dir);
+    WIN32_FIND_DATA info;
+    struct dirent  *data;
+    int             ret;
+
+    if (!dir->dd_handle) {
+        char *dirname;
+        if (*dir->dd_name) {
+            size_t n = strlen(dir->dd_name);
+            if ((dir = (char*)mem_a(n+5))) {
+                platform_strncpy(dirname,     dir->dd_name, n);
+                platform_strncpy(dirname + n, "\\*.*",      4);
+            }
+        } else {
+            if (!(dirname = util_strdup("\\*.*")))
+                return NULL;
+        }
+
+        dir->dd_handle = (long)FindFirstFile(dirname, &info);
+        mem_d(dirname);
+        ret = !(!dir->dd_handle);
+    } else if (dir->dd_handle != -11) {
+        ret = FindNextFile((HANDLE)dir->dd_handle, &info);
+    } else {
+        ret = 0;
+    }
+
+    if (!ret)
+        return NULL;
+
+    if ((data = (struct dirent*)mem_a(sizeof(struct dirent)))) {
+        platform_strncpy(data->d_name, info.cFileName, FILENAME_MAX - 1);
+        data->d_name[FILENAME_MAX - 1] = '\0';
+        data->d_namelen                = strlen(data->d_name);
+    }
+
+    return data;
 }
 
 int platform_istty(int fd) {
index f1116addb166d6721275e2cfe5cb8300e3864829..0914545aca6ad7ea0a2baddc7144ac8302d9c1ff 100644 (file)
 #include <stdio.h>
 
 #ifdef _WIN32
-#   undef  STDERR_FILENO
-#   undef  STDOUT_FILENO
-#   define STDERR_FILENO 2
-#   define STDOUT_FILENO 1
-
+#   ifndef STDERR_FILENO
+#       define STDERR_FILENO 2
+#   endif
+#   ifndef STDOUT_FILENO
+#       define STDOUT_FILENO 1
+#   endif
 #   ifndef __MINGW32__
 #       define _WIN32_LEAN_AND_MEAN
 #       include <windows.h>