scummvm random work
[patches.git] / eject-2.1.5-handle-spaces.patch
CommitLineData
5e993f12 1Index: eject.c
2===================================================================
3RCS file: /cvsroot/eject/eject/eject/eject.c,v
4retrieving revision 1.10
5diff -u -p -r1.10 eject.c
6--- eject.c 15 Jul 2006 23:28:28 -0000 1.10
7+++ eject.c 14 Oct 2006 20:23:29 -0000
8@@ -370,6 +370,30 @@ static int FileExists(const char *name,
9
10
11 /*
12+ * Linux mangles spaces in mount points by changing them to an octal string
13+ * of '\040'. So lets scan the mount point and fix it up by replacing all
14+ * occurrences off '\0##' with the ASCII value of 0##. Requires a writable
15+ * string as input as we mangle in place. Some of this was taken from the
16+ * util-linux package.
17+ */
18+#define octalify(a) ((a) & 7)
19+#define tooctal(s) (64*octalify(s[1]) + 8*octalify(s[2]) + octalify(s[3]))
20+#define isoctal(a) (((a) & ~7) == '0')
21+static char *DeMangleMount(char *s)
22+{
23+ char *tmp = s;
24+ while ((tmp = strchr(tmp, '\\')) != NULL) {
25+ if (isoctal(tmp[1]) && isoctal(tmp[2]) && isoctal(tmp[3])) {
26+ tmp[0] = tooctal(tmp);
27+ memmove(tmp+1, tmp+4, strlen(tmp)-3);
28+ }
29+ ++tmp;
30+ }
31+ return s;
32+}
33+
34+
35+/*
36 * Given name, such as foo, see if any of the following exist:
37 *
38 * foo (if foo starts with '.' or '/')
39@@ -884,8 +908,8 @@ static int MountedDevice(const char *nam
40 if (((strcmp(s1, name) == 0) || (strcmp(s2, name) == 0)) ||
41 ((maj != -1) && (maj == mtabmaj) && (min == mtabmin))) {
42 FCLOSE(fp);
43- *deviceName = strdup(s1);
44- *mountName = strdup(s2);
45+ *deviceName = DeMangleMount(strdup(s1));
46+ *mountName = DeMangleMount(strdup(s2));
47 return 1;
48 }
49 }
50@@ -928,8 +952,8 @@ static int MountableDevice(const char *n
51 rc = sscanf(line, "%1023s %1023s", s1, s2);
52 if (rc >= 2 && s1[0] != '#' && strcmp(s2, name) == 0) {
53 FCLOSE(fp);
54- *deviceName = strdup(s1);
55- *mountName = strdup(s2);
56+ *deviceName = DeMangleMount(strdup(s1));
57+ *mountName = DeMangleMount(strdup(s2));
58 return 1;
59 }
60 }