summaryrefslogtreecommitdiff
path: root/perlio.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2001-11-15 14:35:55 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2001-11-15 14:35:55 +0000
commited53a2bb7f04bc2b3b8eb8450d6e00842e9d7680 (patch)
tree10062f2208f919244a92f310db85dea6bcbfd6df /perlio.c
parent313c9f5cdd9c2881025ae80733bae6b0f1cb11f9 (diff)
downloadperl-ed53a2bb7f04bc2b3b8eb8450d6e00842e9d7680.tar.gz
Fix for "perlio bug in koi8-r encoding". The problem
seemed to be that binmode() always flushed the handle, which is not so good when switching encodings. Fixed, added Matt Sergeant's testcase, documented in perlfunc/binmode, also added a pointer about disciplines to perlfunc/open, and in general cleaned up and reformatted the open entry. p4raw-id: //depot/perl@13019
Diffstat (limited to 'perlio.c')
-rw-r--r--perlio.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/perlio.c b/perlio.c
index 8e8b859e5d..88b3758345 100644
--- a/perlio.c
+++ b/perlio.c
@@ -1072,16 +1072,19 @@ PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int mode, const char *names)
PerlIO_debug("PerlIO_binmode f=%p %s %c %x %s\n",
f, PerlIOBase(f)->tab->name, iotype, mode,
(names) ? names : "(Null)");
- PerlIO_flush(f);
- if (!names && (O_TEXT != O_BINARY && (mode & O_BINARY))) {
- PerlIO *top = f;
- while (*top) {
- if (PerlIOBase(top)->tab == &PerlIO_crlf) {
- PerlIOBase(top)->flags &= ~PERLIO_F_CRLF;
- break;
+ /* Can't flush if switching encodings. */
+ if (!(names && memEQ(names, ":encoding(", 10))) {
+ PerlIO_flush(f);
+ if (!names && (O_TEXT != O_BINARY && (mode & O_BINARY))) {
+ PerlIO *top = f;
+ while (*top) {
+ if (PerlIOBase(top)->tab == &PerlIO_crlf) {
+ PerlIOBase(top)->flags &= ~PERLIO_F_CRLF;
+ break;
+ }
+ top = PerlIONext(top);
+ PerlIO_flush(top);
}
- top = PerlIONext(top);
- PerlIO_flush(top);
}
}
return PerlIO_apply_layers(aTHX_ f, NULL, names) == 0 ? TRUE : FALSE;