summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-21 02:43:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-21 02:43:48 +0000
commitc3d6f8d74f444fd6a4681016b62f0d00d6200846 (patch)
tree9b872cea8555afcfedbaf06be6b88e2c50712b86 /dir.c
parent338a3073bdc581676ce9fb4632d119e7a585de57 (diff)
* dir.c (dir_chdir, check_dirname): get rid of optimization-out.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/dir.c b/dir.c
index 02b0351222..f9de4a3668 100644
--- a/dir.c
+++ b/dir.c
@@ -749,7 +749,6 @@ dir_close(VALUE dir)
static void
dir_chdir(VALUE path)
{
- path = rb_str_encode_ospath(path);
if (chdir(RSTRING_PTR(path)) < 0)
rb_sys_fail(RSTRING_PTR(path));
}
@@ -832,6 +831,7 @@ dir_s_chdir(int argc, VALUE *argv, VALUE obj)
rb_secure(2);
if (rb_scan_args(argc, argv, "01", &path) == 1) {
FilePathValue(path);
+ path = rb_str_encode_ospath(path);
}
else {
const char *dist = getenv("HOME");
@@ -849,9 +849,8 @@ dir_s_chdir(int argc, VALUE *argv, VALUE obj)
if (rb_block_given_p()) {
struct chdir_data args;
- char *cwd = my_getcwd();
- args.old_path = rb_tainted_str_new2(cwd); xfree(cwd);
+ args.old_path = rb_str_encode_ospath(rb_dir_getwd());
args.new_path = path;
args.done = FALSE;
return rb_ensure(chdir_yield, (VALUE)&args, chdir_restore, (VALUE)&args);
@@ -896,14 +895,16 @@ dir_s_getwd(VALUE dir)
static void
check_dirname(volatile VALUE *dir)
{
+ VALUE d = *dir;
char *path, *pend;
rb_secure(2);
- FilePathValue(*dir);
- path = RSTRING_PTR(*dir);
+ FilePathValue(d);
+ path = RSTRING_PTR(d);
if (path && *(pend = rb_path_end(rb_path_skip_prefix(path)))) {
- *dir = rb_str_new(path, pend - path);
+ d = rb_str_subseq(d, 0, pend - path);
}
+ *dir = rb_str_encode_ospath(d);
}
#if defined(HAVE_CHROOT)
@@ -920,8 +921,6 @@ static VALUE
dir_s_chroot(VALUE dir, VALUE path)
{
check_dirname(&path);
-
- path = rb_str_encode_ospath(path);
if (chroot(RSTRING_PTR(path)) == -1)
rb_sys_fail(RSTRING_PTR(path));
@@ -960,7 +959,6 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
}
check_dirname(&path);
- path = rb_str_encode_ospath(path);
if (mkdir(RSTRING_PTR(path), mode) == -1)
rb_sys_fail(RSTRING_PTR(path));
@@ -980,7 +978,6 @@ static VALUE
dir_s_rmdir(VALUE obj, VALUE dir)
{
check_dirname(&dir);
- dir = rb_str_encode_ospath(dir);
if (rmdir(RSTRING_PTR(dir)) < 0)
rb_sys_fail(RSTRING_PTR(dir));