diff --git a/ChangeLog b/ChangeLog index 1c4074b55c..6eecb9480a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Jun 22 00:01:36 2008 NAKAMURA Usaku + + * io.c (rb_io_binmode_p, argf_binmode_p, Init_IO): new method + IO#binmode? and ARGF.binmode? [ruby-dev:35148] + Sat Jun 21 17:33:50 2008 NAKAMURA Usaku * win32/win32.c (rb_w32_spawn): no longer support P_WAIT. diff --git a/io.c b/io.c index 44c7de5aec..8bed3446fe 100644 --- a/io.c +++ b/io.c @@ -3167,6 +3167,20 @@ rb_io_binmode_m(VALUE io) return io; } +/* + * call-seq: + * ios.binmode? => true or false + * + * Returns true if ios is binmode. + */ +static VALUE +rb_io_binmode_p(VALUE io) +{ + rb_io_t *fptr; + GetOpenFile(io, fptr); + return fptr->mode & FMODE_BINMODE ? Qtrue : Qfalse; +} + static const char* rb_io_flags_mode(int flags) { @@ -7377,6 +7391,12 @@ argf_binmode_m(VALUE argf) return argf; } +static VALUE +argf_binmode_p(VALUE argf) +{ + return argf_binmode ? Qtrue : Qfalse; +} + static VALUE argf_skip(VALUE argf) { @@ -7703,6 +7723,7 @@ Init_IO(void) rb_define_method(rb_cIO, "isatty", rb_io_isatty, 0); rb_define_method(rb_cIO, "tty?", rb_io_isatty, 0); rb_define_method(rb_cIO, "binmode", rb_io_binmode_m, 0); + rb_define_method(rb_cIO, "binmode?", rb_io_binmode_p, 0); rb_define_method(rb_cIO, "sysseek", rb_io_sysseek, -1); rb_define_method(rb_cIO, "ioctl", rb_io_ioctl, -1); @@ -7769,6 +7790,7 @@ Init_IO(void) rb_define_method(rb_cARGF, "eof", argf_eof, 0); rb_define_method(rb_cARGF, "eof?", argf_eof, 0); rb_define_method(rb_cARGF, "binmode", argf_binmode_m, 0); + rb_define_method(rb_cARGF, "binmode?", argf_binmode_p, 0); rb_define_method(rb_cARGF, "filename", argf_filename, 0); rb_define_method(rb_cARGF, "path", argf_filename, 0);