changeset 247:4b36eaaf80c3

First attempt at fixing the drive letter problem on Windows Absolute paths in windows cannot be detected by simply checking for a leading slash, even in MinGW. Instead, apply a heuristic that looks for either a leading slash or a letter followed by a colon. This heuristic is only activated on windows builds.
author William Astle <lost@l-w.ca>
date Thu, 24 Jan 2013 21:00:00 -0700
parents b97460509c3d
children 891bab942b5a
files lwasm/input.c
diffstat 1 files changed, 24 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/input.c	Thu Jan 24 20:58:30 2013 -0700
+++ b/lwasm/input.c	Thu Jan 24 21:00:00 2013 -0700
@@ -82,6 +82,28 @@
 
 struct ifl *ifl_head = NULL;
 
+static int input_isabsolute(const char *s)
+{
+#if defined(WIN32) || defined(WIN64)
+	// aiming for the root of the current drive - treat as absolute
+	if (s[0] == '/')
+		return 1;
+	// check for drive letter stuff
+	if (!s[0] || !s[1])
+		return 0;
+	if (s[1] != ':')
+		return 0;
+	if (isalpha(s[0]))
+		return 1;
+	return 0;
+#else
+	/* this is suitable for unix-like systems */
+	if (s[0] == '/')
+		return 1;
+	return 0;
+#endif
+}
+
 /* this adds real filenames that were opened to a list */
 void input_add_to_resource_list(asmstate_t *as, const char *s)
 {
@@ -208,7 +230,7 @@
 	{
 	case input_type_include:
 		/* first check for absolute path and if so, skip path */
-		if (*s == '/')
+		if (input_isabsolute(s))
 		{
 			/* absolute path */
 			IS -> data = fopen(s, "rb");
@@ -292,7 +314,7 @@
 
 	debug_message(as, 2, "Open file (st) %s", s);
 	/* first check for absolute path and if so, skip path */
-	if (*s == '/')
+	if (input_isabsolute(s))
 	{
 		/* absolute path */
 		debug_message(as, 2, "Open file (st abs) %s", s);