0001-io.c-io_s_write-io_s_binwrite-Re-add-IO.write-binwri.patch

Run Paint Run Run, 03/07/2010 02:32 AM

Download (2.86 KB)

View differences:

io.c
7904 7904
    return rb_ensure(io_s_read, (VALUE)&arg, rb_io_close, arg.io);
7905 7905
}
7906 7906

  
7907
struct write_arg {
7908
    VALUE io, str;
7909
};
7910

  
7911
static VALUE
7912
io_s_write(struct write_arg *arg)
7913
{
7914
    return io_write(arg->io, arg->str, 0);
7915
}
7916

  
7917
/* Opens _path_ with mode _mode_, writes _str_ to it, then closes the file. */
7918
static VALUE
7919
io_s_write_mode(VALUE path, VALUE str, const char *mode, VALUE io)
7920
{
7921
    struct write_arg warg;
7922
    FilePathValue(path);
7923
    warg.str = str;
7924
    warg.io = rb_io_open(path, rb_str_new_cstr(mode), Qnil, Qnil);
7925
    if (NIL_P(warg.io)) return Qnil;
7926
    return rb_ensure(io_s_write, (VALUE)&warg, rb_io_close, warg.io);
7927
}
7928

  
7929
/*
7930
 *  call-seq:
7931
 *     IO.write(path, string)   => fixnum
7932
 *
7933
 *  Opens and truncates the file at <tt>path</tt>, writes <tt>string</tt> to
7934
 *  it, then returns the number of bytes written. If you need more control
7935
 *  over the writing process consider IO.open instead.
7936
 *
7937
 *     IO.write("testfile", "0123456789")      #=> 10
7938
 */
7939

  
7940
static VALUE
7941
rb_io_s_write(int argc, VALUE path, VALUE str, VALUE io)
7942
{
7943
    const char *mode = "w";
7944
    return io_s_write_mode(path, str, mode, io);
7945
}
7946

  
7947
/*
7948
 *  call-seq:
7949
 *     IO.binwrite(path, string)   => fixnum
7950
 *
7951
 *  Opens the file <tt>path</tt> in binary mode (open mode: "wb:ASCII-8BIT"),
7952
 *  writes <tt>string</tt> to it, then returns the number of bytes written. If
7953
 *  you need more control over the writing process consider IO.open instead.
7954
 *
7955
 *     IO.binwrite("testfile", "0123456789")      #=> 10
7956
 */
7957

  
7958
static VALUE
7959
rb_io_s_binwrite(int argc, VALUE path, VALUE str, VALUE io)
7960
{
7961
    const char *mode = "wb:ASCII-8BIT";
7962
    return io_s_write_mode(path, str, mode, io);
7963
}
7907 7964
struct copy_stream_struct {
7908 7965
    VALUE src;
7909 7966
    VALUE dst;
......
9707 9764
    rb_define_singleton_method(rb_cIO, "readlines", rb_io_s_readlines, -1);
9708 9765
    rb_define_singleton_method(rb_cIO, "read", rb_io_s_read, -1);
9709 9766
    rb_define_singleton_method(rb_cIO, "binread", rb_io_s_binread, -1);
9767
    rb_define_singleton_method(rb_cIO, "write", rb_io_s_write, 2);
9768
    rb_define_singleton_method(rb_cIO, "binwrite", rb_io_s_binwrite, 2);
9710 9769
    rb_define_singleton_method(rb_cIO, "select", rb_f_select, -1);
9711 9770
    rb_define_singleton_method(rb_cIO, "pipe", rb_io_s_pipe, -1);
9712 9771
    rb_define_singleton_method(rb_cIO, "try_convert", rb_io_s_try_convert, 1);
9713
-