CVS: winex/files drive.c,1.46,1.47

[email protected] 31 Jul 2007 17:37:46 -0000
Newsgroups gmane.comp.emulators.winex.cvs
Message-ID <[email protected]>
Subject: winex/files drive.c,1.46,1.47Update of /var/lib/cvsd/cvsroot/winex/files
In directory agravaine:/tmp/cvs-serv21873/files

Modified Files:
	drive.c 
Log Message:

- handle octal escapes when parsing /proc/mounts


Index: drive.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/files/drive.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- drive.c	30 Mar 2007 21:43:27 -0000	1.46
+++ drive.c	31 Jul 2007 17:37:44 -0000	1.47
@@ -349,6 +349,7 @@
 	char *device_path, *mount_path, *mount_type;
 	int i;
 	DOSDRIVE *drive;
+	size_t len;
 	struct stat drive_stat_buffer;
 	
 	mtab_file = fopen ("/proc/mounts", "r");
@@ -385,8 +386,41 @@
 		/* we dont want trailing /'s on our paths */
 		while (*p && !DRIVE_isspace(*p)) p++;
 		mount_path = heap_strndup (p_tmp, p - p_tmp);
-		if (mount_path[strlen(mount_path)] == '/')
-			mount_path[strlen(mount_path)] = '\0';
+		len = strlen (mount_path);
+		if (mount_path[len] == '/')
+		{
+			mount_path[len] = '\0';
+			len--;
+		}
+
+                /* Handle octal escapes in mount path - newer linux distros
+                   can use these to escape spaces in the mount point */
+                for (i = 0; (len > 3) && (i < (len - 3)); i++)
+                {
+                   int value;
+
+                   if (mount_path[i] != '\\')
+                      continue;
+
+                   /* Check for valid escape */
+                   if ((i >= (len - 3)) || !isdigit (mount_path[i + 1]) ||
+                       !isdigit (mount_path[i + 2]) ||
+                       !isdigit (mount_path[i + 3]) ||
+                       (mount_path[i + 1] > '3'))
+                      continue;
+
+                   /* Convert octal to an integer */
+                   value = mount_path[i + 1] - '0';
+                   value = (value << 3) | (mount_path[i + 2] - '0');
+                   value = (value << 3) | (mount_path[i + 3] - '0');
+
+                   /* replace \\ with the value, move rest of string down
+                      by 3 */
+                   mount_path[i] = (char)value;
+                   memmove (&mount_path[i + 1], &mount_path[i + 4],
+                            len - i - 2);
+                   len -= 3;
+                }
 		
 		while (*p && DRIVE_isspace(*p)) p++;