diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2021-12-20 09:59:45 +1300 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2021-12-21 12:25:42 +1300 |
commit | 49166fc74a9cd0bf48baa08d32e020183ad46723 (patch) | |
tree | 204d42f388ec2a0a0301b1696d7d9ccb6b8ba486 /file.c | |
parent | 71bf5cef75b9d244a06261c9fc0b84fbe5a1592f (diff) |
Improved exception usage/classes.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5303
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -2518,19 +2518,23 @@ rb_file_birthtime(VALUE obj) off_t rb_file_size(VALUE file) { - rb_io_t *fptr; - struct stat st; + if (RB_TYPE_P(file, T_FILE)) { + rb_io_t *fptr; + struct stat st; - RB_IO_POINTER(file, fptr); - if (fptr->mode & FMODE_WRITABLE) { - rb_io_flush_raw(file, 0); - } + RB_IO_POINTER(file, fptr); + if (fptr->mode & FMODE_WRITABLE) { + rb_io_flush_raw(file, 0); + } - if (fstat(fptr->fd, &st) == -1) { - rb_sys_fail_path(fptr->pathv); - } + if (fstat(fptr->fd, &st) == -1) { + rb_sys_fail_path(fptr->pathv); + } - return st.st_size; + return st.st_size; + } else { + return NUM2OFFT(rb_funcall(file, idSize, 0)); + } } static VALUE |