summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-16 02:23:51 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-16 02:23:51 +0000
commitb215b9742ecdc7c3771d305400f72bd76946277e (patch)
treef5396b6cd4309a728f97aeb3244c1fee14e42cb0 /file.c
parentdcff8e84d3528af37d7540a8613f9bd247623b1a (diff)
* file.c (file_expand_path): ignore dname if it has different
drive letter or UNC. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/file.c b/file.c
index b6205cf899..64fe824ec2 100644
--- a/file.c
+++ b/file.c
@@ -2518,6 +2518,12 @@ static const char file_alt_separator[] = {FILE_ALT_SEPARATOR, '\0'};
# define CharNext(p) ((p) + 1)
#endif
+#if defined(DOSISH_UNC)
+#define has_unc(buf) (isdirsep((buf)[0]) && isdirsep((buf)[1]))
+#else
+#define has_unc(buf) 0
+#endif
+
#ifdef DOSISH_DRIVE_LETTER
static inline int
has_drive_letter(const char *buf)
@@ -2556,6 +2562,19 @@ getcwdofdrv(int drv)
}
return drvcwd;
}
+
+static inline int
+not_same_drive(VALUE path, int drive)
+{
+ const char *p = RSTRING_PTR(path);
+ if (RSTRING_LEN(path) < 2) return 0;
+ if (has_drive_letter(p)) {
+ return TOLOWER(p[0]) != TOLOWER(drive);
+ }
+ else {
+ return has_unc(p);
+ }
+}
#endif
static inline char *
@@ -2781,7 +2800,7 @@ file_expand_path(VALUE fname, VALUE dname, int abs_mode, VALUE result)
else {
/* specified drive, but not full path */
int same = 0;
- if (!NIL_P(dname)) {
+ if (!NIL_P(dname) || !not_same_drive(dname, s[0])) {
file_expand_path(dname, Qnil, abs_mode, result);
BUFINIT();
if (has_drive_letter(p) && TOLOWER(p[0]) == TOLOWER(s[0])) {