Browse code

Bare minimum changes to get Windows builds running again.

Andrew Alderwick authored on 31/01/2023 17:05:01
Showing 2 changed files
... ...
@@ -70,6 +70,7 @@ CC="${CC:-cc}"
70 70
 CFLAGS="${CFLAGS:--std=c89 -Wall -Wno-unknown-pragmas}"
71 71
 case "$(uname -s 2>/dev/null)" in
72 72
 MSYS_NT*|MINGW*) # MSYS2 on Windows
73
+	FILE_LDFLAGS="-liberty"
73 74
 	if [ $console = 1 ];
74 75
 	then
75 76
 		UXNEMU_LDFLAGS="-static $(sdl2-config --cflags --static-libs | sed -e 's/ -mwindows//g')"
... ...
@@ -98,8 +99,8 @@ fi
98 99
 
99 100
 echo "Building.."
100 101
 ${CC} ${CFLAGS} src/uxnasm.c -o bin/uxnasm
101
-${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/devices/datetime.c src/devices/mouse.c src/devices/controller.c src/devices/screen.c src/devices/audio.c src/uxnemu.c ${UXNEMU_LDFLAGS} -o bin/uxnemu
102
-${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/devices/datetime.c src/uxncli.c -o bin/uxncli
102
+${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/devices/datetime.c src/devices/mouse.c src/devices/controller.c src/devices/screen.c src/devices/audio.c src/uxnemu.c ${UXNEMU_LDFLAGS} ${FILE_LDFLAGS} -o bin/uxnemu
103
+${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/devices/datetime.c src/uxncli.c ${FILE_LDFLAGS} -o bin/uxncli
103 104
 
104 105
 if [ $install = 1 ]
105 106
 then
... ...
@@ -8,6 +8,11 @@
8 8
 #include <sys/stat.h>
9 9
 #include <unistd.h>
10 10
 
11
+#ifdef _WIN32
12
+#include <libiberty/libiberty.h>
13
+#define realpath(s, dummy) lrealpath(s)
14
+#endif
15
+
11 16
 #ifndef PATH_MAX
12 17
 #define PATH_MAX 4096
13 18
 #endif
... ...
@@ -84,14 +89,17 @@ file_read_dir(UxnFile *c, char *dest, Uint16 len)
84 89
 			continue;
85 90
 		if(strcmp(c->de->d_name, "..") == 0) {
86 91
 			/* hide "sandbox/.." */
87
-			char cwd[PATH_MAX] = {'\0'}, t[PATH_MAX] = {'\0'};
92
+			char cwd[PATH_MAX] = {'\0'}, *t;
88 93
 			/* Note there's [currently] no way of chdir()ing from uxn, so $PWD
89 94
 			 * is always the sandbox top level. */
90 95
 			getcwd(cwd, sizeof(cwd));
91 96
 			/* We already checked that c->current_filename exists so don't need a wrapper. */
92
-			realpath(c->current_filename, t);
93
-			if(strcmp(cwd, t) == 0)
97
+			t = realpath(c->current_filename, NULL);
98
+			if(strcmp(cwd, t) == 0) {
99
+				free(t);
94 100
 				continue;
101
+			}
102
+			free(t);
95 103
 		}
96 104
 		if(strlen(c->current_filename) + 1 + strlen(c->de->d_name) < sizeof(pathname))
97 105
 			sprintf(pathname, "%s/%s", c->current_filename, c->de->d_name);
... ...
@@ -108,7 +116,7 @@ file_read_dir(UxnFile *c, char *dest, Uint16 len)
108 116
 static char *
109 117
 retry_realpath(const char *file_name)
110 118
 {
111
-	char r[PATH_MAX] = {'\0'}, p[PATH_MAX] = {'\0'}, *x;
119
+	char *r, p[PATH_MAX] = {'\0'}, *x;
112 120
 	if(file_name == NULL) {
113 121
 		errno = EINVAL;
114 122
 		return NULL;
... ...
@@ -123,7 +131,7 @@ retry_realpath(const char *file_name)
123 131
 		strcat(p, "/"); /* TODO: use a macro instead of '/' for the path delimiter */
124 132
 	}
125 133
 	strcat(p, file_name);
126
-	while(realpath(p, r) == NULL) {
134
+	while((r = realpath(p, NULL)) == NULL) {
127 135
 		if(errno != ENOENT)
128 136
 			return NULL;
129 137
 		x = strrchr(p, '/'); /* TODO: path delimiter macro */
... ...
@@ -134,6 +142,7 @@ retry_realpath(const char *file_name)
134 142
 	}
135 143
 	x = malloc(strlen(r) + 1);
136 144
 	strcpy(x, r);
145
+	free(r);
137 146
 	return x;
138 147
 }
139 148