Feature #1081 » 0001-io.c-io_s_write-io_s_binwrite-Re-add-IO.write-binwri.patch
| io.c | ||
|---|---|---|
| 
         return rb_ensure(io_s_read, (VALUE)&arg, rb_io_close, arg.io); 
   | 
||
| 
     } 
   | 
||
| 
     struct write_arg { 
   | 
||
| 
         VALUE io, str; 
   | 
||
| 
     }; 
   | 
||
| 
     static VALUE 
   | 
||
| 
     io_s_write(struct write_arg *arg) 
   | 
||
| 
     { 
   | 
||
| 
         return io_write(arg->io, arg->str, 0); 
   | 
||
| 
     } 
   | 
||
| 
     /* Opens _path_ with mode _mode_, writes _str_ to it, then closes the file. */ 
   | 
||
| 
     static VALUE 
   | 
||
| 
     io_s_write_mode(VALUE path, VALUE str, const char *mode, VALUE io) 
   | 
||
| 
     { 
   | 
||
| 
         struct write_arg warg; 
   | 
||
| 
         FilePathValue(path); 
   | 
||
| 
         warg.str = str; 
   | 
||
| 
         warg.io = rb_io_open(path, rb_str_new_cstr(mode), Qnil, Qnil); 
   | 
||
| 
         if (NIL_P(warg.io)) return Qnil; 
   | 
||
| 
         return rb_ensure(io_s_write, (VALUE)&warg, rb_io_close, warg.io); 
   | 
||
| 
     } 
   | 
||
| 
     /* 
   | 
||
| 
      *  call-seq: 
   | 
||
| 
      *     IO.write(path, string)   => fixnum 
   | 
||
| 
      * 
   | 
||
| 
      *  Opens and truncates the file at <tt>path</tt>, writes <tt>string</tt> to 
   | 
||
| 
      *  it, then returns the number of bytes written. If you need more control 
   | 
||
| 
      *  over the writing process consider IO.open instead. 
   | 
||
| 
      * 
   | 
||
| 
      *     IO.write("testfile", "0123456789")      #=> 10 
   | 
||
| 
      */ 
   | 
||
| 
     static VALUE 
   | 
||
| 
     rb_io_s_write(int argc, VALUE path, VALUE str, VALUE io) 
   | 
||
| 
     { 
   | 
||
| 
         const char *mode = "w"; 
   | 
||
| 
         return io_s_write_mode(path, str, mode, io); 
   | 
||
| 
     } 
   | 
||
| 
     /* 
   | 
||
| 
      *  call-seq: 
   | 
||
| 
      *     IO.binwrite(path, string)   => fixnum 
   | 
||
| 
      * 
   | 
||
| 
      *  Opens the file <tt>path</tt> in binary mode (open mode: "wb:ASCII-8BIT"), 
   | 
||
| 
      *  writes <tt>string</tt> to it, then returns the number of bytes written. If 
   | 
||
| 
      *  you need more control over the writing process consider IO.open instead. 
   | 
||
| 
      * 
   | 
||
| 
      *     IO.binwrite("testfile", "0123456789")      #=> 10 
   | 
||
| 
      */ 
   | 
||
| 
     static VALUE 
   | 
||
| 
     rb_io_s_binwrite(int argc, VALUE path, VALUE str, VALUE io) 
   | 
||
| 
     { 
   | 
||
| 
         const char *mode = "wb:ASCII-8BIT"; 
   | 
||
| 
         return io_s_write_mode(path, str, mode, io); 
   | 
||
| 
     } 
   | 
||
| 
     struct copy_stream_struct { 
   | 
||
| 
         VALUE src; 
   | 
||
| 
         VALUE dst; 
   | 
||
| ... | ... | |
| 
         rb_define_singleton_method(rb_cIO, "readlines", rb_io_s_readlines, -1); 
   | 
||
| 
         rb_define_singleton_method(rb_cIO, "read", rb_io_s_read, -1); 
   | 
||
| 
         rb_define_singleton_method(rb_cIO, "binread", rb_io_s_binread, -1); 
   | 
||
| 
         rb_define_singleton_method(rb_cIO, "write", rb_io_s_write, 2); 
   | 
||
| 
         rb_define_singleton_method(rb_cIO, "binwrite", rb_io_s_binwrite, 2); 
   | 
||
| 
         rb_define_singleton_method(rb_cIO, "select", rb_f_select, -1); 
   | 
||
| 
         rb_define_singleton_method(rb_cIO, "pipe", rb_io_s_pipe, -1); 
   | 
||
| 
         rb_define_singleton_method(rb_cIO, "try_convert", rb_io_s_try_convert, 1); 
   | 
||