From e9bde1e4e4cd790da6b0ee464cda61cce5a327b8 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Fri, 11 Oct 2013 05:09:55 -0400 Subject: [PATCH] Add back the correct directory handling for msvc --- Makefile | 4 ++-- msvc.c | 49 +++++++++++++++++++++++++++++++++++++++++++++---- platform.h | 11 ++++++----- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 0b57b9c..bfc68c7 100644 --- 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 2c6a3ed..3f44797 100644 --- a/msvc.c +++ b/msvc.c @@ -22,7 +22,6 @@ */ #include #include -#include #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) { diff --git a/platform.h b/platform.h index f1116ad..0914545 100644 --- a/platform.h +++ b/platform.h @@ -28,11 +28,12 @@ #include #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