summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-02-14 16:09:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-02-14 16:09:07 +0000
commitf2d07eb82dd00174c15a10cd9a2e1bcdc0eb668e (patch)
treead834634caf3a4f66d6ff165cf2518683594dc30 /file.c
parentbfa0275833b60de39c8f890d6f47045d1ef4b26e (diff)
* file.c (file_expand_path): fix surplus path separators while
expanding at root directory. [ruby-dev:19572] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/file.c b/file.c
index 9996423dd3..165e6eeec2 100644
--- a/file.c
+++ b/file.c
@@ -1577,6 +1577,17 @@ file_expand_path(fname, dname, result)
tainted = 1;
getcwd(buf, MAXPATHLEN);
p = &buf[2];
+ if (!isdirsep(*p)) {
+ while (*p && !isdirsep(*p)) {
+ p = CharNext(p);
+ }
+ if (*p) {
+ p++;
+ while (*p && !isdirsep(*p)) {
+ p = CharNext(p);
+ }
+ }
+ }
b = s;
while (*s && !isdirsep(*s)) {
s = CharNext(s);
@@ -1598,15 +1609,18 @@ file_expand_path(fname, dname, result)
strcpy(buf, dir);
free(dir);
}
- p = chompdirsep(skiproot(buf));
+ p = skiproot(buf);
+ if (*p)
+ p = chompdirsep(p);
+ else
+ --p;
}
else {
- while (*s && isdirsep(*s)) {
- *p++ = '/';
- BUFCHECK(p >= pend);
- s++;
- }
- if (p > buf && *s) p--;
+ b = s;
+ do s++; while (isdirsep(*s));
+ p = buf + (s - b) - 1;
+ BUFCHECK(p >= pend);
+ memset(buf, '/', p - buf);
}
*p = '/';
@@ -1667,16 +1681,7 @@ file_expand_path(fname, dname, result)
memcpy(++p, b, s-b);
p += s-b;
}
-#ifdef DOSISH_DRIVE_LETTER
- else if (ISALPHA(buf[0]) && (buf[1] == ':') && isdirsep(buf[2])) {
- /* root directory needs a trailing backslash,
- otherwise it mean the current directory of the drive */
- if (p == (buf+2)) p++;
- }
- else if (isdirsep(buf[0]) && isdirsep(buf[1])) {
- if (p == (buf+1)) p++;
- }
-#endif
+ if (p == skiproot(buf) - 1) p++;
if (tainted) OBJ_TAINT(result);
RSTRING(result)->len = p - buf;