aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-13 12:30:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-13 12:30:35 +0000
commit16f37446f777cc120619bccc5a66358158a14bee (patch)
tree7f402774d7974a4860690ceff1b148cf985a4a99 /io.c
parentc6e9425c064d8378d537eaefc4705b07d72a46a0 (diff)
downloadruby-16f37446f777cc120619bccc5a66358158a14bee.tar.gz
io.c: simplify rb_io_modestr_fmode
* io.c (io_encname_bom_p): needs len always. * io.c (rb_io_modestr_fmode): check BOM only after a colon. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/io.c b/io.c
index 150c99c0db..fd8f6f1a97 100644
--- a/io.c
+++ b/io.c
@@ -4893,10 +4893,6 @@ io_encname_bom_p(const char *name, long len)
{
static const char bom_prefix[] = "bom|utf-";
enum {bom_prefix_len = (int)sizeof(bom_prefix) - 1};
- if (!len) {
- const char *p = strchr(name, ':');
- len = p ? (long)(p - name) : (long)strlen(name);
- }
return len > bom_prefix_len && STRNCASECMP(name, bom_prefix, bom_prefix_len) == 0;
}
@@ -4935,7 +4931,9 @@ rb_io_modestr_fmode(const char *modestr)
default:
goto error;
case ':':
- p = m;
+ p = strchr(m, ':');
+ if (io_encname_bom_p(m, p ? (long)(p - m) : (long)strlen(m)))
+ fmode |= FMODE_SETENC_BY_BOM;
goto finished;
}
}
@@ -4943,8 +4941,6 @@ rb_io_modestr_fmode(const char *modestr)
finished:
if ((fmode & FMODE_BINMODE) && (fmode & FMODE_TEXTMODE))
goto error;
- if (p && io_encname_bom_p(p, 0))
- fmode |= FMODE_SETENC_BY_BOM;
return fmode;
}