summaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-10 18:00:36 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-10 18:00:36 +0000
commit2aa36f16b943a77bee284eb337452c3c1405e74a (patch)
treed60f2b768b4df041ad89639ed13fccce49e5e419 /io.c
parent3746f0071618242fe68c2268cdb2c10e480e50e9 (diff)
downloadruby-2aa36f16b943a77bee284eb337452c3c1405e74a.tar.gz
ruby-2aa36f16b943a77bee284eb337452c3c1405e74a.tar.xz
ruby-2aa36f16b943a77bee284eb337452c3c1405e74a.zip
* io.c (io_binwrite): extracted from io_fwrite.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@19290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c67
1 files changed, 37 insertions, 30 deletions
diff --git a/io.c b/io.c
index a3ca6486b..2a6b042ea 100644
--- a/io.c
+++ b/io.c
@@ -744,40 +744,12 @@ make_writeconv(rb_io_t *fptr)
}
/* writing functions */
+
static long
-io_fwrite(VALUE str, rb_io_t *fptr)
+io_binwrite(VALUE str, rb_io_t *fptr)
{
long len, n, r, l, offset = 0;
- if (NEED_WRITECONV(fptr)) {
- VALUE common_encoding = Qnil;
- make_writeconv(fptr);
-
- if (fptr->writeconv) {
- if (!NIL_P(fptr->writeconv_asciicompat))
- common_encoding = fptr->writeconv_asciicompat;
- else if (!rb_enc_asciicompat(rb_enc_get(str))) {
- rb_raise(rb_eArgError, "ASCII incompatible string written for text mode IO without encoding conversion: %s",
- rb_enc_name(rb_enc_get(str)));
- }
- }
- else {
- if (fptr->encs.enc2)
- common_encoding = rb_enc_from_encoding(fptr->encs.enc2);
- else
- common_encoding = rb_enc_from_encoding(fptr->encs.enc);
- }
-
- if (!NIL_P(common_encoding)) {
- str = rb_str_transcode(str, common_encoding,
- fptr->writeconv_pre_ecflags, fptr->writeconv_pre_ecopts);
- }
-
- if (fptr->writeconv) {
- str = rb_econv_str_convert(fptr->writeconv, str, ECONV_PARTIAL_INPUT);
- }
- }
-
len = RSTRING_LEN(str);
if ((n = len) <= 0) return n;
if (fptr->wbuf == NULL && !(fptr->mode & FMODE_SYNC)) {
@@ -840,6 +812,41 @@ io_fwrite(VALUE str, rb_io_t *fptr)
return len;
}
+static long
+io_fwrite(VALUE str, rb_io_t *fptr)
+{
+ if (NEED_WRITECONV(fptr)) {
+ VALUE common_encoding = Qnil;
+ make_writeconv(fptr);
+
+ if (fptr->writeconv) {
+ if (!NIL_P(fptr->writeconv_asciicompat))
+ common_encoding = fptr->writeconv_asciicompat;
+ else if (!rb_enc_asciicompat(rb_enc_get(str))) {
+ rb_raise(rb_eArgError, "ASCII incompatible string written for text mode IO without encoding conversion: %s",
+ rb_enc_name(rb_enc_get(str)));
+ }
+ }
+ else {
+ if (fptr->encs.enc2)
+ common_encoding = rb_enc_from_encoding(fptr->encs.enc2);
+ else
+ common_encoding = rb_enc_from_encoding(fptr->encs.enc);
+ }
+
+ if (!NIL_P(common_encoding)) {
+ str = rb_str_transcode(str, common_encoding,
+ fptr->writeconv_pre_ecflags, fptr->writeconv_pre_ecopts);
+ }
+
+ if (fptr->writeconv) {
+ str = rb_econv_str_convert(fptr->writeconv, str, ECONV_PARTIAL_INPUT);
+ }
+ }
+
+ return io_binwrite(str, fptr);
+}
+
long
rb_io_fwrite(const char *ptr, long len, FILE *f)
{