# 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
*/
#include <string.h>
#include <stdlib.h>
-#include <io.h>
#include "platform.h"
}
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) {
#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>