summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-30 19:29:56 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-30 19:29:56 +0000
commit2c87fffec417971fdc7c3fa457dd17ac2be451c6 (patch)
tree86048e66b320132808f7a6e5a18f2c8c8d8cd51c /io.c
parent5e78715f2ca14906b6df594ffebe823955160c95 (diff)
* io.c (rb_f_readline): should raise EOFError at the end of
files. [ruby-dev:22458] * io.c (argf_read): should concatenate input files when length argument is nil. [ruby-dev:22450] * io.c (argf_read): should update supplied string buffer (2nd argument) even when IO#read is called multiple times. * io.c: should initialize lineno by zero. [ruby-dev:22460] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/io.c b/io.c
index 3ccb375876..40d8568bbf 100644
--- a/io.c
+++ b/io.c
@@ -59,7 +59,7 @@
#include <sys/stat.h>
/* EMX has sys/param.h, but.. */
-#if defined(HAVE_SYS_PARAM_H) && !(defined(__EMX__) || defined(__HIUX_MPP__))
+#if defined(HAVE_SYS_PAAM_H) && !(defined(__EMX__) || defined(__HIUX_MPP__))
# include <sys/param.h>
#endif
@@ -110,7 +110,7 @@ struct timeval rb_time_interval _((VALUE));
static VALUE filename, current_file;
static int gets_lineno;
static int init_p = 0, next_p = 0;
-static VALUE lineno;
+static VALUE lineno = INT2FIX(0);
#if defined(__VMS)
#define fopen(file_spec, mode) fopen(file_spec, mode, "rfm=stmlf")
@@ -4105,7 +4105,8 @@ rb_f_readline(argc, argv)
{
VALUE line;
- NEXT_ARGF_FORWARD();
+ if (!next_argv()) rb_eof_error();
+ ARGF_FORWARD();
line = rb_f_gets(argc, argv);
if (NIL_P(line)) {
rb_eof_error();
@@ -4913,23 +4914,22 @@ argf_read(argc, argv)
int argc;
VALUE *argv;
{
- VALUE tmp, str;
+ VALUE tmp, str, length;
long len = 0;
- if (argc == 1 && !NIL_P(argv[0]))
+ rb_scan_args(argc, argv, "02", &length, &str);
+ if (!NIL_P(length)) {
len = NUM2LONG(argv[0]);
- str = Qnil;
+ }
+ if (!NIL_P(str)) {
+ StringValue(str);
+ rb_str_resize(str,0);
+ argv[1] = Qnil;
+ }
retry:
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);
- }
+ if (NIL_P(str)) return rb_str_new(0,0);
return str;
}
if (TYPE(current_file) != T_FILE) {
@@ -4940,14 +4940,14 @@ argf_read(argc, argv)
}
if (NIL_P(str)) str = tmp;
else rb_str_append(str, tmp);
- if (NIL_P(tmp) || argc == 0) {
+ if (NIL_P(tmp) || NIL_P(argv[0])) {
if (next_p != -1) {
argf_close(current_file);
next_p = 1;
goto retry;
}
}
- else if (argc == 1) {
+ else if (argc >= 1) {
if (RSTRING(str)->len < len) {
len -= RSTRING(str)->len;
argv[0] = INT2NUM(len);