Avoid using `mrb_funcall()` from `mruby-io` gem.

parent 55482063
...@@ -11,6 +11,11 @@ class File < IO ...@@ -11,6 +11,11 @@ class File < IO
end end
end end
def mtime
t = self._mtime
t && Time.at(t)
end
def self.join(*names) def self.join(*names)
return "" if names.empty? return "" if names.empty?
......
...@@ -390,15 +390,12 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass) ...@@ -390,15 +390,12 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass)
static mrb_value static mrb_value
mrb_file_mtime(mrb_state *mrb, mrb_value self) mrb_file_mtime(mrb_state *mrb, mrb_value self)
{ {
mrb_value obj; int fd = mrb_io_fileno(mrb, self);
struct stat st; struct stat st;
int fd;
obj = mrb_obj_value(mrb_class_get(mrb, "Time"));
fd = mrb_io_fileno(mrb, self);
if (fstat(fd, &st) == -1) if (fstat(fd, &st) == -1)
return mrb_false_value(); return mrb_false_value();
return mrb_funcall(mrb, obj, "at", 1, mrb_fixnum_value(st.st_mtime)); return mrb_fixnum_value((mrb_int)st.st_mtime);
} }
static mrb_value static mrb_value
...@@ -608,7 +605,7 @@ mrb_init_file(mrb_state *mrb) ...@@ -608,7 +605,7 @@ mrb_init_file(mrb_state *mrb)
mrb_define_class_method(mrb, file, "_gethome", mrb_file__gethome, MRB_ARGS_OPT(1)); mrb_define_class_method(mrb, file, "_gethome", mrb_file__gethome, MRB_ARGS_OPT(1));
mrb_define_method(mrb, file, "flock", mrb_file_flock, MRB_ARGS_REQ(1)); mrb_define_method(mrb, file, "flock", mrb_file_flock, MRB_ARGS_REQ(1));
mrb_define_method(mrb, file, "mtime", mrb_file_mtime, MRB_ARGS_NONE()); mrb_define_method(mrb, file, "_mtime", mrb_file_mtime, MRB_ARGS_NONE());
mrb_define_method(mrb, file, "size", mrb_file_size, MRB_ARGS_NONE()); mrb_define_method(mrb, file, "size", mrb_file_size, MRB_ARGS_NONE());
mrb_define_method(mrb, file, "truncate", mrb_file_truncate, MRB_ARGS_REQ(1)); mrb_define_method(mrb, file, "truncate", mrb_file_truncate, MRB_ARGS_REQ(1));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment