Project

General

Profile

Feature #6528 ยป 0001-ext-pathname-pathname.c-add-Pathname-write-and-Pathn.patch

niku (niku _), 06/02/2012 02:37 PM

View differences:

ext/pathname/pathname.c
}
/*
* call-seq:
* pathname.write(string, [offset]) -> fixnum
* pathname.write(string, [offset], open_args) -> fixnum
*
* See <tt>IO.write</tt>. Returns the byte length written.
*
*/
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, "12", &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
*
* See <tt>IO.binwrite</tt>. Returns the byte length written.
*
*/
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, "12", &args[1], &args[2], &args[3]);
return rb_funcall2(rb_cIO, rb_intern("binwrite"), 1+n, args);
}
/*
* See <tt>File.atime</tt>. Returns last access time.
*/
static VALUE
......
* - #binread(*args)
* - #readlines(*args)
* - #sysopen(*args)
* - #write(string, *args)
* - #binwrite(string, *args)
*
* === Utilities
*
......
rb_define_method(rb_cPathname, "binread", path_binread, -1);
rb_define_method(rb_cPathname, "readlines", path_readlines, -1);
rb_define_method(rb_cPathname, "sysopen", path_sysopen, -1);
rb_define_method(rb_cPathname, "write", path_write, -1);
rb_define_method(rb_cPathname, "binwrite", path_binwrite, -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);
test/pathname/test_pathname.rb
}
end
def test_write
with_tmpchdir('rubytest-pathname') {|dir|
Pathname("a").write("1\n2\n")
assert_equal("1\n2\n", open("a") {|f| f.read })
}
end
def test_binwrite
with_tmpchdir('rubytest-pathname') {|dir|
Pathname("a").binwrite("abc")
assert_equal("abc", open("a") {|f| f.read })
}
end
def test_atime
assert_kind_of(Time, Pathname(__FILE__).atime)
end
    (1-1/1)