diff options
| author | Tomoyuki Sahara <[email protected]> | 2015-10-20 16:03:02 +0900 |
|---|---|---|
| committer | Tomoyuki Sahara <[email protected]> | 2015-10-20 16:03:02 +0900 |
| commit | 828551f86ce9a2dd0c1a8af39c8ac99ecc0859a0 (patch) | |
| tree | b1d6e09391fcfb2cc8a3fbb04b82f1b297ba1608 | |
| parent | db7d82967944fca2ef3581a5a5d3417c807b8efc (diff) | |
| download | mruby-828551f86ce9a2dd0c1a8af39c8ac99ecc0859a0.tar.gz mruby-828551f86ce9a2dd0c1a8af39c8ac99ecc0859a0.zip | |
off_t can be larger than mrb_int.
| -rw-r--r-- | src/io.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -525,7 +525,8 @@ mrb_value mrb_io_sysseek(mrb_state *mrb, mrb_value io) { struct mrb_io *fptr; - mrb_int pos, offset, whence = -1; + off_t pos; + mrb_int offset, whence = -1; mrb_get_args(mrb, "i|i", &offset, &whence); if (whence < 0) { @@ -534,11 +535,14 @@ mrb_io_sysseek(mrb_state *mrb, mrb_value io) fptr = (struct mrb_io *)mrb_get_datatype(mrb, io, &mrb_io_type); pos = lseek(fptr->fd, offset, whence); - if (pos < 0) { + if (pos == -1) { mrb_sys_fail(mrb, "sysseek"); } - - return mrb_fixnum_value(pos); + if (pos > MRB_INT_MAX) { + return mrb_float_value(mrb, (mrb_float)pos); + } else { + return mrb_fixnum_value(pos); + } } mrb_value |
