diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-26 17:11:12 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-26 17:11:12 +0000 |
commit | 40465862bdb23bddfe1d8b52f21962a4ccb9208a (patch) | |
tree | 27b85c6c7934833a436f56e7adb747b0e61ea1f5 /io.c | |
parent | 9e159579e0a074e5723c4eec4381ea56979b5b95 (diff) |
* io.c (next_argv): warn always for stdin on inplace edit mode.
* io.c (read_all): need to check string value.
* io.c (argf_read): allow ARGF.read(nil). [ruby-dev:22433]
* io.c (rb_f_backquote): need not to check nil result.
[ruby-core:02078]
* io.c (rb_io_getline): should return nil when read_all gives
empty string, even when nil rs is specified. [ruby-core:02077]
* pack.c (pack_pack): add sign check for 'i', and 'l'.
[ruby-dev:22427]
* bignum.c (rb_quad_pack): add range check for 'quad int'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@5312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 39 |
1 files changed, 27 insertions, 12 deletions
@@ -786,6 +786,7 @@ read_all(fptr, siz, str) str = rb_tainted_str_new(0, siz); } else { + StringValue(str); rb_str_resize(str, siz); } for (;;) { @@ -1027,6 +1028,7 @@ rb_io_getline(rs, fptr) rb_io_check_readable(fptr); if (NIL_P(rs)) { str = read_all(fptr, 0, Qnil); + if (RSTRING(str)->len == 0) return Qnil; } else if (rs == rb_default_rs) { return rb_io_getline_fast(fptr, '\n'); @@ -1346,8 +1348,8 @@ fptr_finalize(fptr, noraise) if (fptr->f2) { f2 = fileno(fptr->f2); while ((n2 = fclose(fptr->f2)) < 0) { + e = errno; if (!rb_io_wait_writable(f2)) { - e = errno; break; } if (!fptr->f2) break; @@ -2990,23 +2992,22 @@ next_argv() } else { next_p = -1; - current_file = rb_stdin; - filename = rb_str_new2("-"); } init_p = 1; gets_lineno = 0; } - retry: if (next_p == 1) { next_p = 0; + retry: if (RARRAY(rb_argv)->len > 0) { filename = rb_ary_shift(rb_argv); fn = StringValuePtr(filename); if (strlen(fn) == 1 && fn[0] == '-') { current_file = rb_stdin; if (ruby_inplace_mode) { - rb_warn("Can't do inplace edit for stdio"); + rb_warn("Can't do inplace edit for stdio; skipping"); + goto retry; } } else { @@ -3077,12 +3078,17 @@ next_argv() } else { init_p = 0; - if (ruby_inplace_mode) { - rb_stdout = orig_stdout; - } return Qfalse; } } + else if (next_p == -1) { + current_file = rb_stdin; + filename = rb_str_new2("-"); + if (ruby_inplace_mode) { + rb_warn("Can't do inplace edit for stdio"); + rb_stdout = orig_stdout; + } + } return Qtrue; } @@ -3222,10 +3228,8 @@ rb_f_backquote(obj, str) GetOpenFile(port, fptr); result = read_all(fptr, remain_size(fptr), Qnil); - rb_io_close(port); - if (NIL_P(result)) return rb_str_new(0,0); return result; } @@ -3828,11 +3832,22 @@ argf_read(argc, argv) VALUE tmp, str; long len = 0; - if (argc == 1) len = NUM2LONG(argv[0]); + if (argc == 1 && !NIL_P(argv[0])) + len = NUM2LONG(argv[0]); str = Qnil; retry: - if (!next_argv()) return str; + if (!next_argv()) { + if (NIL_P(str)) { + VALUE length; + + rb_scan_args(argc, argv, "02", &length, &str); + if (NIL_P(str)) return rb_str_new(0,0); + StringValue(str); + rb_str_resize(str,0); + } + return str; + } if (TYPE(current_file) != T_FILE) { tmp = argf_forward(); } |