summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-28 06:18:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-28 06:18:30 +0000
commit58c2571b597b278e93362f86983b18f7d8c19ad2 (patch)
tree90fe8a70b6ac1c65b2fb834b88d5d8baf26c9101
parentffa153f282b8fb94734a3b33ba83cc8566a0231f (diff)
io.c: preserve encodings
* io.c (argf_next_argv): preserve encodings in warning messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--io.c21
-rw-r--r--test/ruby/test_argf.rb7
2 files changed, 18 insertions, 10 deletions
diff --git a/io.c b/io.c
index 62a948093d..f5792542b3 100644
--- a/io.c
+++ b/io.c
@@ -7878,7 +7878,7 @@ argf_next_argv(VALUE argf)
if (ARGF.next_p == 1) {
retry:
if (RARRAY_LEN(ARGF.argv) > 0) {
- ARGF.filename = rb_ary_shift(ARGF.argv);
+ ARGF.filename = rb_str_encode_ospath(rb_ary_shift(ARGF.argv));
fn = StringValueCStr(ARGF.filename);
if (strlen(fn) == 1 && fn[0] == '-') {
ARGF.current_file = rb_stdin;
@@ -7904,21 +7904,22 @@ argf_next_argv(VALUE argf)
}
fstat(fr, &st);
if (*ARGF.inplace) {
- str = rb_str_new2(fn);
+ str = rb_str_dup(ARGF.filename);
rb_str_cat2(str, ARGF.inplace);
+ /* TODO: encoding of ARGF.inplace */
#ifdef NO_SAFE_RENAME
(void)close(fr);
(void)unlink(RSTRING_PTR(str));
if (rename(fn, RSTRING_PTR(str)) < 0) {
- rb_warn("Can't rename %s to %s: %s, skipping file",
- fn, RSTRING_PTR(str), strerror(errno));
+ rb_warn("Can't rename %"PRIsVALUE" to %"PRIsVALUE": %s, skipping file",
+ ARGF.filename, str, strerror(errno));
goto retry;
}
fr = rb_sysopen(str, O_RDONLY, 0);
#else
if (rename(fn, RSTRING_PTR(str)) < 0) {
- rb_warn("Can't rename %s to %s: %s, skipping file",
- fn, RSTRING_PTR(str), strerror(errno));
+ rb_warn("Can't rename %"PRIsVALUE" to %"PRIsVALUE": %s, skipping file",
+ ARGF.filename, str, strerror(errno));
close(fr);
goto retry;
}
@@ -7929,8 +7930,8 @@ argf_next_argv(VALUE argf)
rb_fatal("Can't do inplace edit without backup");
#else
if (unlink(fn) < 0) {
- rb_warn("Can't remove %s: %s, skipping file",
- fn, strerror(errno));
+ rb_warn("Can't remove %"PRIsVALUE": %s, skipping file",
+ ARGF.filename, strerror(errno));
close(fr);
goto retry;
}
@@ -7953,8 +7954,8 @@ argf_next_argv(VALUE argf)
#endif
if (err && getuid() == 0 && st2.st_uid == 0) {
const char *wkfn = RSTRING_PTR(ARGF.filename);
- rb_warn("Can't set owner/group of %s to same as %s: %s, skipping file",
- wkfn, fn, strerror(errno));
+ rb_warn("Can't set owner/group of %"PRIsVALUE" to same as %"PRIsVALUE": %s, skipping file",
+ ARGF.filename, str, strerror(errno));
(void)close(fr);
(void)close(fw);
(void)unlink(wkfn);
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index fb869561a1..95d694116f 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -212,6 +212,13 @@ class TestArgf < Test::Unit::TestCase
assert_equal([], r)
assert_equal("foo\nbar\nbaz\n", File.read(t.path))
end
+
+ base = "argf-\u{30c6 30b9 30c8}"
+ name = "#{@tmpdir}/#{base}"
+ File.write(name, "foo")
+ argf = ARGF.class.new(name)
+ argf.inplace_mode = '/\\:'
+ assert_warning(/#{base}/) {argf.gets}
end
def test_inplace_no_backup