From 2034fe610fd9da3781f4a1e39079128da812748c Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 25 Aug 2010 13:11:43 +0000 Subject: * ext/pathname/pathname.c (path_binread): Pathname#binread translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/pathname/lib/pathname.rb | 4 ---- ext/pathname/pathname.c | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8757e8bce7..198b4462f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Aug 25 22:11:11 2010 Tanaka Akira + + * ext/pathname/pathname.c (path_binread): Pathname#binread translated + from pathname.rb. + Wed Aug 25 03:42:43 2010 NAKAMURA Usaku * ext/dl/cfunc.c (rb_dlcfunc_call): workaround for VC9 for x64. diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index 203fe930fc..0bc8e3bfa5 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -485,10 +485,6 @@ end class Pathname # * IO * - # See IO.binread. Returns all the bytes from the file, or the first +N+ - # if specified. - def binread(*args) IO.binread(@path, *args) end - # See IO.readlines. Returns all the lines from the file. def readlines(*args) IO.readlines(@path, *args) end diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index 76bbbd5c0d..874581dfbd 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -281,6 +281,25 @@ path_read(int argc, VALUE *argv, VALUE self) return rb_funcall2(rb_cIO, rb_intern("read"), 1+n, args); } +/* + * call-seq: + * pathname.binread([length [, offset]]) -> string + * + * See IO.binread. Returns all the bytes from the file, or the first +N+ + * if specified. + * + */ +static VALUE +path_binread(int argc, VALUE *argv, VALUE self) +{ + VALUE args[3]; + int n; + + args[0] = get_strpath(self); + n = rb_scan_args(argc, argv, "02", &args[1], &args[2]); + return rb_funcall2(rb_cIO, rb_intern("binread"), 1+n, args); +} + /* * See File.atime. Returns last access time. */ @@ -742,6 +761,7 @@ Init_pathname() rb_define_method(rb_cPathname, "realdirpath", path_realdirpath, -1); rb_define_method(rb_cPathname, "each_line", path_each_line, -1); rb_define_method(rb_cPathname, "read", path_read, -1); + rb_define_method(rb_cPathname, "binread", path_binread, -1); rb_define_method(rb_cPathname, "atime", path_atime, 0); rb_define_method(rb_cPathname, "ctime", path_ctime, 0); rb_define_method(rb_cPathname, "mtime", path_mtime, 0); -- cgit v1.2.3