summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-21 13:21:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-21 13:21:47 +0000
commite4b2293712c52b089aa5e179a1b3d5571e93e733 (patch)
tree72b271178aae87ecfca7a377db8edee03740b6a3 /file.c
parentcbb5d57a2a0c17a562b557f90d7995dac5e105d6 (diff)
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@9578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/file.c b/file.c
index e427cedade..37c83f208a 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,15 +2584,31 @@ 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))) {
if (NIL_P(fext) || !(f = rmext(name, StringValueCStr(fext)))) {