[PATCH] Fixed the Windows issues regarding files and added a thing to make it compile properly on MinGW32.
Export this patch
---
src/devices/file.c | 21 +++++++++++++++++ ----
src/uxnemu.c | 5 ++++ -
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/devices/file.c b/src/devices/file.c
index 6edbf59..76d8338 100644
--- a/src/devices/file.c
+++ b/src/devices/file.c
@@ -11,6 +11,11 @@
#ifdef _WIN32
#include <libiberty/libiberty.h>
#define realpath(s, dummy) lrealpath(s)
+ #define DIR_SEP_CHAR '\\'
+ #define DIR_SEP_STR "\\"
+ #else
+ #define DIR_SEP_CHAR '/'
+ #define DIR_SEP_STR "/"
#endif
#ifndef PATH_MAX
@@ -124,17 +129,21 @@ retry_realpath(const char *file_name)
errno = ENAMETOOLONG;
return NULL;
}
- if(file_name[0] != '/') {
+ #ifdef _WIN32
+ if(file_name[0] != DIR_SEP_CHAR && ((strlen(file_name)>2 && file_name[1] != ':') || strlen(file_name)<=2) ) {
+ #else
+ if(file_name[0] != DIR_SEP_CHAR) {
+ #endif
/* TODO: use a macro instead of '/' for absolute path first character so that other systems can work */
/* if a relative path, prepend cwd */
getcwd(p, sizeof(p));
- strcat(p, "/"); /* TODO: use a macro instead of '/' for the path delimiter */
+ strcat(p, DIR_SEP_STR); /* TODO: use a macro instead of '/' for the path delimiter */
}
strcat(p, file_name);
while((r = realpath(p, NULL)) == NULL) {
if(errno != ENOENT)
return NULL;
- x = strrchr(p, '/'); /* TODO: path delimiter macro */
+ x = strrchr(p, DIR_SEP_CHAR); /* TODO: path delimiter macro */
if(x)
*x = '\0';
else
@@ -149,7 +158,11 @@ file_check_sandbox(UxnFile *c)
char *x, *rp, cwd[PATH_MAX] = {'\0'};
x = getcwd(cwd, sizeof(cwd));
rp = retry_realpath(c->current_filename);
+ #ifdef _WIN32
+ if(rp == NULL || (x && strncasecmp(cwd, rp, strlen(cwd)) != 0)) { /* strncasecmp provided by libiberty */
+ #else
if(rp == NULL || (x && strncmp(cwd, rp, strlen(cwd)) != 0)) {
+ #endif
c->outside_sandbox = 1;
fprintf(stderr, "file warning: blocked attempt to access %s outside of sandbox\n", c->current_filename);
}
@@ -213,7 +226,7 @@ file_write(UxnFile *c, void *src, Uint16 len, Uint8 flags)
static Uint16
file_stat(UxnFile *c, void *dest, Uint16 len)
{
- char *basename = strrchr(c->current_filename, '/');
+ char *basename = strrchr(c->current_filename, DIR_SEP_CHAR);
if(c->outside_sandbox) return 0;
if(basename != NULL)
basename++;
diff --git a/src/uxnemu.c b/src/uxnemu.c
index 2303055..7cbfd34 100644
--- a/src/uxnemu.c
+++ b/src/uxnemu.c
@@ -16,8 +16,11 @@
#include "devices/controller.h"
#include "devices/mouse.h"
#include "devices/datetime.h"
- #ifdef _WIN32
+ #if defined(_WIN32) && defined(_WIN32_WINNT) && _WIN32_WINNT > 0x0602
#include <processthreadsapi.h>
+ #elif defined(_WIN32)
+ #include <windows.h>
+ #include <string.h>
#endif
#pragma GCC diagnostic pop
#pragma clang diagnostic pop
--
2.37.1.windows.1