なかだです。 At Sat, 15 Feb 2003 12:06:47 +0900, pegacorn / jcom.home.ne.jp wrote: > > それからテストケースを追加していて気づいたんですが、UNC上での > > expand_pathはこうなるはずではないかと思うんですが、どうでしょう > > か。 > > > > File.expand_path("/", "//machine/share/sub") => "//machine/share" > > 私は cygwin か mswin/mingw かによって異なると思います。 > > cygwin: > File.expand_path("/", "//machine/share/sub") => "/" > > mswin/mingw: > File.expand_path("/", "//machine/share/sub") => "//machine/share" > > 理由は、"/" は cygwin 環境では絶対パス、mswin/mingw 環境 > (というか普通の Windows 環境)では相対パスだと思うからです。 カレントディレクトリがUNC上にあるときはいいんですが、よく見ると 今は、ドライブ/UNCなしのフルパスで指定したときは、dnameを無視し てますね。 > ついでに、ドライブレター指定の場合だと以下のようになると思います。 > > cygwin: > File.expand_path("/", "C:/sub") => "/" > > mswin/mingw: > File.expand_path("/", "C:/sub") => "C:/" > # 1.6.7 だとこうならない… これは現状通りということで。 あと、pwd.hがないとFile.expand_path("~nouser")みたいのが展開も されずエラーにもならないようです。
Index: file.c =================================================================== RCS file: //sharui/cvs/ruby/src/ruby/file.c,v retrieving revision 1.136 diff -u -2 -p -r1.136 file.c --- file.c 14 Feb 2003 16:09:07 -0000 1.136 +++ file.c 15 Feb 2003 04:47:43 -0000 @@ -1425,4 +1425,14 @@ skiproot(path) } +static inline char * +nextdirsep(s) + const char *s; +{ + while (*s && !isdirsep(*s)) { + s = CharNext(s); + } + return (char *)s; +} + static char * strrdirsep(path) @@ -1514,10 +1524,7 @@ file_expand_path(fname, dname, result) #ifdef HAVE_PWD_H struct passwd *pwPtr; - s++; #endif - b = s; - while (*s && !isdirsep(*s)) { - s = CharNext(s); - } + s++; + s = nextdirsep(b = s); BUFCHECK(p + (s-b) >= pend); memcpy(p, b, s-b); @@ -1528,5 +1535,7 @@ file_expand_path(fname, dname, result) if (!pwPtr) { endpwent(); +#endif rb_raise(rb_eArgError, "user %s doesn't exist", buf); +#ifdef HAVE_PWD_H } BUFCHECK(strlen(pwPtr->pw_dir) > buflen); @@ -1543,11 +1552,8 @@ file_expand_path(fname, dname, result) /* specified drive letter, and full path */ /* skip drive letter */ - b = s; - while (*s && !isdirsep(*s)) { - s = CharNext(s); - } - BUFCHECK(p + (s-b) >= pend); - memcpy(p, b, s-b); - p += s-b; + BUFCHECK(p + 2 >= pend); + memcpy(p, s, 2); + p += 2; + s += 2 } else { @@ -1563,5 +1569,5 @@ file_expand_path(fname, dname, result) } if (!same) { - getcwdofdrv(*s, buf, MAXPATHLEN); + getcwdofdrv(*s, buf, buflen); tainted = 1; } @@ -1571,31 +1577,4 @@ file_expand_path(fname, dname, result) } #endif -#ifdef DOSISH - else if (isdirsep(*s) && !is_absolute_path(s)) { - /* specified full path, but not drive letter */ - /* we need to get the drive letter */ - 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); - } - BUFCHECK(p + (s-b) >= pend); - memcpy(p, b, s-b); - p += s-b; - } -#endif else if (!is_absolute_path(s)) { if (!NIL_P(dname)) { @@ -1611,7 +1590,20 @@ file_expand_path(fname, dname, result) } p = skiproot(buf); +#ifdef DOSISH + if (isdirsep(*s)) { + /* specified full path, but not drive letter nor UNC */ + if (has_drive_letter(buf)) { + p = &buf[2]; + } + else if (isdirsep(buf[0]) && isdirsep(buf[1])) { + /* we need to get the UNC share name */ + if (*(p = nextdirsep(p))) p = nextdirsep(p + 1); + } + } + else +#endif if (*p) p = chompdirsep(p); - else + else if (p > buf) --p; } @@ -2542,5 +2534,5 @@ is_absolute_path(path) { #ifdef DOSISH_DRIVE_LETTER - if (ISALPHA(path[0]) && path[1] == ':' && isdirsep(path[2])) return 1; + if (has_drive_letter(path) && isdirsep(path[2])) return 1; #endif #ifdef DOSISH_UNC
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦