* 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
This commit is contained in:
nobu 2010-03-16 02:23:51 +00:00
parent dcff8e84d3
commit b215b9742e
2 changed files with 25 additions and 1 deletions

View File

@ -1,3 +1,8 @@
Tue Mar 16 11:23:42 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (file_expand_path): ignore dname if it has different
drive letter or UNC.
Tue Mar 16 07:16:56 2010 Tanaka Akira <akr@fsij.org> Tue Mar 16 07:16:56 2010 Tanaka Akira <akr@fsij.org>
* tool/transcode-tblgen.rb: redundant loop removed. * tool/transcode-tblgen.rb: redundant loop removed.

21
file.c
View File

@ -2518,6 +2518,12 @@ static const char file_alt_separator[] = {FILE_ALT_SEPARATOR, '\0'};
# define CharNext(p) ((p) + 1) # define CharNext(p) ((p) + 1)
#endif #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 #ifdef DOSISH_DRIVE_LETTER
static inline int static inline int
has_drive_letter(const char *buf) has_drive_letter(const char *buf)
@ -2556,6 +2562,19 @@ getcwdofdrv(int drv)
} }
return drvcwd; 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 #endif
static inline char * static inline char *
@ -2781,7 +2800,7 @@ file_expand_path(VALUE fname, VALUE dname, int abs_mode, VALUE result)
else { else {
/* specified drive, but not full path */ /* specified drive, but not full path */
int same = 0; 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); file_expand_path(dname, Qnil, abs_mode, result);
BUFINIT(); BUFINIT();
if (has_drive_letter(p) && TOLOWER(p[0]) == TOLOWER(s[0])) { if (has_drive_letter(p) && TOLOWER(p[0]) == TOLOWER(s[0])) {