diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-23 02:23:42 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-23 02:23:42 +0000 |
commit | e479931145c0375671bbacedf6b772845771fccd (patch) | |
tree | 46aca87ad648da3ee8f5caf5a433c0e3193f74fc /io.c | |
parent | c2deb77dcb45dd6164e4ae30913dfaa19268768a (diff) | |
download | ruby-e479931145c0375671bbacedf6b772845771fccd.tar.gz ruby-e479931145c0375671bbacedf6b772845771fccd.tar.xz ruby-e479931145c0375671bbacedf6b772845771fccd.zip |
* io.c (rb_io_extract_modeenc): check :textmode and :binmode in option
hash.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -125,6 +125,7 @@ static VALUE argf; static ID id_write, id_read, id_getc, id_flush, id_readpartial; static VALUE sym_mode, sym_perm, sym_extenc, sym_intenc, sym_encoding, sym_open_args; +static VALUE sym_textmode, sym_binmode; struct timeval rb_time_interval(VALUE); @@ -3864,6 +3865,18 @@ rb_io_extract_modeenc(VALUE *mode_p, VALUE opthash, } if (!NIL_P(opthash)) { + VALUE v; + v = rb_hash_aref(opthash, sym_textmode); + if (RTEST(v)) + flags |= FMODE_TEXTMODE; + v = rb_hash_aref(opthash, sym_binmode); + if (RTEST(v)) { + flags |= FMODE_BINMODE; +#ifdef O_BINARY + modenum |= O_BINARY; +#endif + } + if (io_extract_encoding_option(opthash, &enc, &enc2)) { if (has_enc) { rb_raise(rb_eArgError, "encoding sepecified twice"); @@ -3871,6 +3884,9 @@ rb_io_extract_modeenc(VALUE *mode_p, VALUE opthash, } } + if ((flags & FMODE_BINMODE) && (flags & FMODE_TEXTMODE)) + rb_raise(rb_eArgError, "both textmode and binmode specified"); + *mode_p = mode; *modenum_p = modenum; @@ -8335,4 +8351,6 @@ Init_IO(void) sym_intenc = ID2SYM(rb_intern("internal_encoding")); sym_encoding = ID2SYM(rb_intern("encoding")); sym_open_args = ID2SYM(rb_intern("open_args")); + sym_textmode = ID2SYM(rb_intern("textmode")); + sym_binmode = ID2SYM(rb_intern("binmode")); } |