diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-06-12 04:09:41 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-06-12 04:09:41 +0000 |
commit | e2890123acf809aae7999c3f1a31892986e20620 (patch) | |
tree | 13fe3ab97919fe060a6f5c28cc5c1a652c3aedb4 /file.c | |
parent | 664007e466247bfffab93f65381ac87724fdf87a (diff) | |
download | ruby-e2890123acf809aae7999c3f1a31892986e20620.tar.gz |
file.c: shrink expanded path
* file.c (expand_path): shrink expanded path which no longer needs
rooms to append. [ruby-core:63114] [Bug #9934]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -3507,6 +3507,16 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na #define EXPAND_PATH_BUFFER() rb_usascii_str_new(0, MAXPATHLEN + 2) +static VALUE +str_shrink(VALUE str) +{ + rb_str_resize(str, RSTRING_LEN(str)); + return str; +} + +#define expand_path(fname, dname, abs_mode, long_name, result) \ + str_shrink(rb_file_expand_path_internal(fname, dname, abs_mode, long_name, result)) + #define check_expand_path_args(fname, dname) \ (((fname) = rb_get_path(fname)), \ (void)(NIL_P(dname) ? (dname) : ((dname) = rb_get_path(dname)))) @@ -3521,13 +3531,13 @@ VALUE rb_file_expand_path(VALUE fname, VALUE dname) { check_expand_path_args(fname, dname); - return rb_file_expand_path_internal(fname, dname, 0, 1, EXPAND_PATH_BUFFER()); + return expand_path(fname, dname, 0, 1, EXPAND_PATH_BUFFER()); } VALUE rb_file_expand_path_fast(VALUE fname, VALUE dname) { - return rb_file_expand_path_internal(fname, dname, 0, 0, EXPAND_PATH_BUFFER()); + return expand_path(fname, dname, 0, 0, EXPAND_PATH_BUFFER()); } /* @@ -3575,7 +3585,7 @@ VALUE rb_file_absolute_path(VALUE fname, VALUE dname) { check_expand_path_args(fname, dname); - return rb_file_expand_path_internal(fname, dname, 1, 1, EXPAND_PATH_BUFFER()); + return expand_path(fname, dname, 1, 1, EXPAND_PATH_BUFFER()); } /* @@ -5519,6 +5529,7 @@ is_explicit_relative(const char *path) static VALUE copy_path_class(VALUE path, VALUE orig) { + str_shrink(path); RBASIC_SET_CLASS(path, rb_obj_class(orig)); OBJ_FREEZE(path); return path; |