From 862215aa023c090d9999dd4ea55792246e92b924 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 21 Nov 2005 13:21:47 +0000 Subject: * file.c (rb_path_skip_prefix, rb_file_s_basename): UNC without path should not be splitted. fixed: [ruby-dev:27776] [ruby-dev:27786] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@9578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ file.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9a1307087..85b683765 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Nov 21 22:19:33 2005 Nobuyoshi Nakada + + * file.c (rb_path_skip_prefix, rb_file_s_basename): UNC without path + should not be splitted. fixed: [ruby-dev:27776] [ruby-dev:27786] + Mon Nov 21 16:03:48 2005 Nobuyoshi Nakada * win32/setup.mk: findstr doesn't exist on win9x. diff --git a/file.c b/file.c index e427cedad..37c83f208 100644 --- a/file.c +++ b/file.c @@ -2214,14 +2214,18 @@ rb_path_next(const char *s) return (char *)s; } +#if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER) #define skipprefix rb_path_skip_prefix +#else +#define skipprefix(path) (path) +#endif char * rb_path_skip_prefix(const char *path) { #if defined(DOSISH_UNC) || defined(DOSISH_DRIVE_LETTER) #ifdef DOSISH_UNC if (isdirsep(path[0]) && isdirsep(path[1])) { - if (*(path = nextdirsep(path + 2))) + if (*(path = nextdirsep(path + 2)) && path[1] && !isdirsep(path[1])) path = nextdirsep(path + 1); return (char *)path; } @@ -2569,6 +2573,9 @@ rb_file_s_basename(int argc, VALUE *argv) { VALUE fname, fext, basename; char *name, *p; +#ifdef DOSISH + char *root; +#endif int f; if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) { @@ -2577,14 +2584,30 @@ rb_file_s_basename(int argc, VALUE *argv) StringValue(fname); if (RSTRING(fname)->len == 0 || !*(name = RSTRING(fname)->ptr)) return fname; - if (!*(name = skiproot(name))) { + name = skipprefix(name); +#ifdef DOSISH + root = name; +#endif + while (isdirsep(*name)) + name++; + if (!*name) { p = name - 1; f = 1; +#ifdef DOSISH + if (name != root) { + /* has slashes */ + } #ifdef DOSISH_DRIVE_LETTER - if (*p == ':') { + else if (*p == ':') { p++; f = 0; } +#endif +#ifdef DOSISH_UNC + else { + p = "/"; + } +#endif #endif } else if (!(p = strrdirsep(name))) { -- cgit