0001-ext-pathname-pathname.c-add-Pathname-write-and-Pathn.patch

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

Download (3.05 KB)

View differences:

ext/pathname/pathname.c
340 340
}
341 341

  
342 342
/*
343
 * call-seq:
344
 *   pathname.write(string, [offset]) -> fixnum
345
 *   pathname.write(string, [offset], open_args) -> fixnum
346
 *
347
 * See <tt>IO.write</tt>.  Returns the byte length written.
348
 *
349
 */
350
static VALUE
351
path_write(int argc, VALUE *argv, VALUE self)
352
{
353
    VALUE args[4];
354
    int n;
355

  
356
    args[0] = get_strpath(self);
357
    n = rb_scan_args(argc, argv, "12", &args[1], &args[2], &args[3]);
358
    return rb_funcall2(rb_cIO, rb_intern("write"), 1+n, args);
359
}
360

  
361
/*
362
 * call-seq:
363
 *   pathname.binwrite(string, [offset]) -> fixnum
364
 *   pathname.binwrite(string, [offset], open_args) -> fixnum
365
 *
366
 * See <tt>IO.binwrite</tt>.  Returns the byte length written.
367
 *
368
 */
369
static VALUE
370
path_binwrite(int argc, VALUE *argv, VALUE self)
371
{
372
    VALUE args[4];
373
    int n;
374

  
375
    args[0] = get_strpath(self);
376
    n = rb_scan_args(argc, argv, "12", &args[1], &args[2], &args[3]);
377
    return rb_funcall2(rb_cIO, rb_intern("binwrite"), 1+n, args);
378
}
379

  
380
/*
343 381
 * See <tt>File.atime</tt>.  Returns last access time.
344 382
 */
345 383
static VALUE
......
1151 1189
 * - #binread(*args)
1152 1190
 * - #readlines(*args)
1153 1191
 * - #sysopen(*args)
1192
 * - #write(string, *args)
1193
 * - #binwrite(string, *args)
1154 1194
 *
1155 1195
 * === Utilities
1156 1196
 *
......
1197 1237
    rb_define_method(rb_cPathname, "binread", path_binread, -1);
1198 1238
    rb_define_method(rb_cPathname, "readlines", path_readlines, -1);
1199 1239
    rb_define_method(rb_cPathname, "sysopen", path_sysopen, -1);
1240
    rb_define_method(rb_cPathname, "write", path_write, -1);
1241
    rb_define_method(rb_cPathname, "binwrite", path_binwrite, -1);
1200 1242
    rb_define_method(rb_cPathname, "atime", path_atime, 0);
1201 1243
    rb_define_method(rb_cPathname, "ctime", path_ctime, 0);
1202 1244
    rb_define_method(rb_cPathname, "mtime", path_mtime, 0);
test/pathname/test_pathname.rb
729 729
    }
730 730
  end
731 731

  
732
  def test_write
733
    with_tmpchdir('rubytest-pathname') {|dir|
734
      Pathname("a").write("1\n2\n")
735
      assert_equal("1\n2\n", open("a") {|f| f.read })
736
    }
737
  end
738

  
739
  def test_binwrite
740
    with_tmpchdir('rubytest-pathname') {|dir|
741
      Pathname("a").binwrite("abc")
742
      assert_equal("abc", open("a") {|f| f.read })
743
    }
744
  end
745

  
732 746
  def test_atime
733 747
    assert_kind_of(Time, Pathname(__FILE__).atime)
734 748
  end
735
-