aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/io.c b/io.c
index ea550592bb..a3a45c0b12 100644
--- a/io.c
+++ b/io.c
@@ -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");