1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* file.c (rb_file_size): new method added. [ruby-core:22088]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22604 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2009-02-24 15:45:16 +00:00
parent 400ded9338
commit 8428347e99
2 changed files with 21 additions and 0 deletions

View file

@ -6,6 +6,10 @@ Wed Feb 25 00:41:21 2009 Akinori MUSHA <knu@iDaemons.org>
* ext/socket/tcpserver.c (tcp_svr_init): Make use of it.
Wed Feb 25 00:28:25 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* file.c (rb_file_size): new method added. [ruby-core:22088]
Wed Feb 25 00:15:15 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/curses/curses.c (curses_colors): new method added. a patch

17
file.c
View file

@ -1807,6 +1807,22 @@ rb_file_ctime(VALUE obj)
return stat_ctime(&st);
}
static VALUE
rb_file_size(VALUE obj)
{
rb_io_t *fptr;
struct stat st;
GetOpenFile(obj, fptr);
if (fptr->mode & FMODE_WRITABLE) {
rb_io_flush(obj);
}
if (fstat(fptr->fd, &st) == -1) {
rb_sys_fail_path(fptr->pathv);
}
return OFFT2NUM(st.st_size);
}
static void
chmod_internal(const char *path, void *mode)
{
@ -4766,6 +4782,7 @@ Init_File(void)
rb_define_method(rb_cFile, "atime", rb_file_atime, 0);
rb_define_method(rb_cFile, "mtime", rb_file_mtime, 0);
rb_define_method(rb_cFile, "ctime", rb_file_ctime, 0);
rb_define_method(rb_cFile, "size", rb_file_size, 0);
rb_define_method(rb_cFile, "chmod", rb_file_chmod, 1);
rb_define_method(rb_cFile, "chown", rb_file_chown, 2);