diff options
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -4786,11 +4786,19 @@ extract_binmode(VALUE opthash, int *fmode) if (!NIL_P(opthash)) { VALUE v; v = rb_hash_aref(opthash, sym_textmode); - if (!NIL_P(v) && RTEST(v)) - *fmode |= FMODE_TEXTMODE; + if (!NIL_P(v)) { + if (*fmode & FMODE_TEXTMODE) + rb_raise(rb_eArgError, "textmode specified twice"); + if (RTEST(v)) + *fmode |= FMODE_TEXTMODE; + } v = rb_hash_aref(opthash, sym_binmode); - if (!NIL_P(v) && RTEST(v)) - *fmode |= FMODE_BINMODE; + if (!NIL_P(v)) { + if (*fmode & FMODE_BINMODE) + rb_raise(rb_eArgError, "binmode specified twice"); + if (RTEST(v)) + *fmode |= FMODE_BINMODE; + } if ((*fmode & FMODE_BINMODE) && (*fmode & FMODE_TEXTMODE)) rb_raise(rb_eArgError, "both textmode and binmode specified"); |