From c3d1fde2b528413f5be2f936a9d7ea899a777fc7 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 4 Apr 2013 11:12:12 +0000 Subject: * ext/pathname/pathname.c (path_write): New method. (path_binwrite): Ditto. [ruby-core:49468] [Feature #7378] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/pathname/pathname.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'ext/pathname/pathname.c') diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index fa67226e84..53f5e7cddd 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -344,6 +344,48 @@ path_binread(int argc, VALUE *argv, VALUE self) return rb_funcall2(rb_cIO, rb_intern("binread"), 1+n, args); } +/* + * call-seq: + * pathname.write(string, [offset] ) => fixnum + * pathname.write(string, [offset], open_args ) => fixnum + * + * Writes +contents+ to the file. + * + * See IO.write. + * + */ +static VALUE +path_write(int argc, VALUE *argv, VALUE self) +{ + VALUE args[4]; + int n; + + args[0] = get_strpath(self); + n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]); + return rb_funcall2(rb_cIO, rb_intern("write"), 1+n, args); +} + +/* + * call-seq: + * pathname.binwrite(string, [offset] ) => fixnum + * pathname.binwrite(string, [offset], open_args ) => fixnum + * + * Writes +contents+ to the file, opening it in binary mode. + * + * See IO.binwrite. + * + */ +static VALUE +path_binwrite(int argc, VALUE *argv, VALUE self) +{ + VALUE args[4]; + int n; + + args[0] = get_strpath(self); + n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]); + return rb_funcall2(rb_cIO, rb_intern("binwrite"), 1+n, args); +} + /* * call-seq: * pathname.readlines(sep=$/ [, open_args]) -> array @@ -1334,6 +1376,8 @@ Init_pathname() rb_define_method(rb_cPathname, "read", path_read, -1); rb_define_method(rb_cPathname, "binread", path_binread, -1); rb_define_method(rb_cPathname, "readlines", path_readlines, -1); + rb_define_method(rb_cPathname, "write", path_write, -1); + rb_define_method(rb_cPathname, "binwrite", path_binwrite, -1); rb_define_method(rb_cPathname, "sysopen", path_sysopen, -1); rb_define_method(rb_cPathname, "atime", path_atime, 0); rb_define_method(rb_cPathname, "ctime", path_ctime, 0); -- cgit v1.2.3