summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-23 07:56:25 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-23 07:56:25 +0000
commitaa5b65b2edf4e79f09b6e9dd488bf160b6a39260 (patch)
tree25fcdc057d9bdced3e0d999754e2cd17a1f40a1d /io.c
parente7d83904cb0698d304fb8631ca34d4434152fd17 (diff)
* io.c (extract_binmode): raise an exception if binmode/textmode
is specified with both vmode and opthash. [ruby-core:42199] [Bug #5918] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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");