diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-03-14 06:23:46 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-03-14 06:23:46 +0000 |
commit | 997b69cb6ac9eb97ea644276f1af886a49c1de03 (patch) | |
tree | 1dffc60dc5f5afbec79dc8d0f314c3355f92dab2 /io.c | |
parent | 4f0870f74b530cdb2de4306d55e966a924a9149c (diff) | |
download | ruby-997b69cb6ac9eb97ea644276f1af886a49c1de03.tar.gz |
* re.c (rb_reg_match): should clear $~ if operand is nil.
* re.c (rb_reg_match2): ditto.
* configure: merge Jonathan Baker's large file support patch
[ruby-talk:35316], with read_all patch in [ruby-talk:35470].
* eval.c (rb_f_abort): optional message argument that be printed
on termination. [new]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 48 |
1 files changed, 34 insertions, 14 deletions
@@ -45,6 +45,16 @@ #include <sys/fcntl.h> #endif +#if !HAVE_OFF_T && !defined(off_t) +# define off_t long +#endif +#if !HAVE_FSEEKO && !defined(fseeko) +# define fseeko fseek +#endif +#if !HAVE_FTELLO && !defined(ftello) +# define ftello ftell +#endif + #ifdef HAVE_SYS_TIME_H # include <sys/time.h> #else @@ -316,13 +326,20 @@ rb_io_tell(io) VALUE io; { OpenFile *fptr; - long pos; + off_t pos; GetOpenFile(io, fptr); - pos = ftell(fptr->f); + pos = ftello(fptr->f); if (ferror(fptr->f)) rb_sys_fail(fptr->path); +#if SIZEOF_OFF_T > SIZEOF_LONG +# if !HAVE_LONG_LONG +# error off_t is bigger than long, but you have no long long... +# endif + return rb_ll2inum(pos); +#else return rb_int2inum(pos); +#endif } #ifndef SEEK_CUR @@ -340,7 +357,7 @@ rb_io_seek(io, offset, whence) long pos; GetOpenFile(io, fptr); - pos = fseek(fptr->f, NUM2LONG(offset), whence); + pos = fseeko(fptr->f, NUM2OFFT(offset), whence); if (pos != 0) rb_sys_fail(fptr->path); clearerr(fptr->f); @@ -371,7 +388,7 @@ rb_io_set_pos(io, offset) long pos; GetOpenFile(io, fptr); - pos = fseek(fptr->f, NUM2LONG(offset), SEEK_SET); + pos = fseeko(fptr->f, NUM2OFFT(offset), SEEK_SET); if (pos != 0) rb_sys_fail(fptr->path); clearerr(fptr->f); @@ -380,12 +397,12 @@ rb_io_set_pos(io, offset) static VALUE rb_io_rewind(io) - VALUE io; + VALUE io; { OpenFile *fptr; GetOpenFile(io, fptr); - if (fseek(fptr->f, 0L, 0) != 0) rb_sys_fail(fptr->path); + if (fseeko(fptr->f, 0L, 0) != 0) rb_sys_fail(fptr->path); clearerr(fptr->f); if (io == current_file) { gets_lineno -= fptr->lineno; @@ -588,7 +605,7 @@ read_all(port) OpenFile *fptr; VALUE str = Qnil; struct stat st; - long siz = BUFSIZ; + off_t siz = BUFSIZ; long bytes = 0; int n; @@ -607,16 +624,19 @@ read_all(port) return rb_str_new(0, 0); } else { - long pos = ftell(fptr->f); + off_t pos = ftello(fptr->f); if (st.st_size > pos && pos >= 0) { siz = st.st_size - pos + 1; + if (siz > LONG_MAX) { + rb_raise(rb_eIOError, "file too big for single read"); + } } } } - str = rb_tainted_str_new(0, siz); + str = rb_tainted_str_new(0, (long)siz); READ_CHECK(fptr->f); for (;;) { - n = io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f); + n = io_fread(RSTRING(str)->ptr+bytes, (long)siz-bytes, fptr->f); if (n == 0 && bytes == 0) { if (feof(fptr->f)) return Qnil; rb_sys_fail(fptr->path); @@ -1986,7 +2006,7 @@ io_reopen(io, nfile) OpenFile *fptr, *orig; char *mode; int fd; - long pos; + off_t pos; nfile = rb_io_get_io(nfile); if (rb_safe_level() >= 4 && (!OBJ_TAINTED(io) || !OBJ_TAINTED(nfile))) { @@ -1997,7 +2017,7 @@ io_reopen(io, nfile) if (fptr == orig) return io; if (orig->mode & FMODE_READABLE) { - pos = ftell(orig->f); + pos = ftello(orig->f); } if (orig->f2) { io_fflush(orig->f2, orig->path); @@ -2032,8 +2052,8 @@ io_reopen(io, nfile) fptr->f = rb_fdopen(fd, mode); } if ((orig->mode & FMODE_READABLE) && pos >= 0) { - fseek(fptr->f, pos, SEEK_SET); - fseek(orig->f, pos, SEEK_SET); + fseeko(fptr->f, pos, SEEK_SET); + fseeko(orig->f, pos, SEEK_SET); } if (fptr->f2) { |