summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/io.c b/io.c
index 8f9c9d5..9a49a23 100644
--- a/io.c
+++ b/io.c
@@ -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();
}