mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
db7f24b362
commit
b96af08add
2 changed files with 3417 additions and 3406 deletions
17
file.c
17
file.c
|
@ -2367,9 +2367,8 @@ rb_path_last_separator(const char *path)
|
|||
return last;
|
||||
}
|
||||
|
||||
#define chompdirsep rb_path_end
|
||||
char *
|
||||
rb_path_end(const char *path)
|
||||
static char *
|
||||
chompdirsep(const char *path)
|
||||
{
|
||||
while (*path) {
|
||||
if (isdirsep(*path)) {
|
||||
|
@ -2384,6 +2383,13 @@ rb_path_end(const char *path)
|
|||
return (char *)path;
|
||||
}
|
||||
|
||||
char *
|
||||
rb_path_end(const char *path)
|
||||
{
|
||||
if (isdirsep(*path)) path++;
|
||||
return chompdirsep(path);
|
||||
}
|
||||
|
||||
#define BUFCHECK(cond) do {\
|
||||
long bdiff = p - buf;\
|
||||
while (cond) {\
|
||||
|
@ -2752,7 +2758,7 @@ rb_file_s_basename(int argc, VALUE *argv)
|
|||
static VALUE
|
||||
rb_file_s_dirname(VALUE klass, VALUE fname)
|
||||
{
|
||||
char *name, *root, *p;
|
||||
const char *name, *root, *p;
|
||||
VALUE dirname;
|
||||
|
||||
name = StringValueCStr(fname);
|
||||
|
@ -2772,8 +2778,9 @@ rb_file_s_dirname(VALUE klass, VALUE fname)
|
|||
return rb_str_new2(".");
|
||||
#ifdef DOSISH_DRIVE_LETTER
|
||||
if (has_drive_letter(name) && isdirsep(*(name + 2))) {
|
||||
const char *top = skiproot(name + 2);
|
||||
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
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue