* file.c (rb_path_end): skip root directory. fixed: [ruby-core:08913]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2006-09-25 12:25:29 +00:00
parent db7f24b362
commit b96af08add
2 changed files with 3417 additions and 3406 deletions

6806
ChangeLog

File diff suppressed because it is too large Load Diff

17
file.c
View File

@ -2367,9 +2367,8 @@ rb_path_last_separator(const char *path)
return last; return last;
} }
#define chompdirsep rb_path_end static char *
char * chompdirsep(const char *path)
rb_path_end(const char *path)
{ {
while (*path) { while (*path) {
if (isdirsep(*path)) { if (isdirsep(*path)) {
@ -2384,6 +2383,13 @@ rb_path_end(const char *path)
return (char *)path; return (char *)path;
} }
char *
rb_path_end(const char *path)
{
if (isdirsep(*path)) path++;
return chompdirsep(path);
}
#define BUFCHECK(cond) do {\ #define BUFCHECK(cond) do {\
long bdiff = p - buf;\ long bdiff = p - buf;\
while (cond) {\ while (cond) {\
@ -2752,7 +2758,7 @@ rb_file_s_basename(int argc, VALUE *argv)
static VALUE static VALUE
rb_file_s_dirname(VALUE klass, VALUE fname) rb_file_s_dirname(VALUE klass, VALUE fname)
{ {
char *name, *root, *p; const char *name, *root, *p;
VALUE dirname; VALUE dirname;
name = StringValueCStr(fname); name = StringValueCStr(fname);
@ -2772,8 +2778,9 @@ rb_file_s_dirname(VALUE klass, VALUE fname)
return rb_str_new2("."); return rb_str_new2(".");
#ifdef DOSISH_DRIVE_LETTER #ifdef DOSISH_DRIVE_LETTER
if (has_drive_letter(name) && isdirsep(*(name + 2))) { if (has_drive_letter(name) && isdirsep(*(name + 2))) {
const char *top = skiproot(name + 2);
dirname = rb_str_new(name, 3); dirname = rb_str_new(name, 3);
rb_str_cat(dirname, skiproot(name + 2), p - skiproot(name + 2)); rb_str_cat(dirname, top, p - top);
} }
else else
#endif #endif