From ff1e38834cd604970c075bd632ce9b1b3ec84bd9 Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Thu, 6 Apr 2006 11:37:21 -0700 Subject: [PATCH] RE: Combining UTF-16 output with :crlf is awkward From: "Jan Dubois" Message-ID: <0bbe01c659e3$d0c334a0$2217a8c0@candy> p4raw-id: //depot/perl@28879 --- perlio.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/perlio.c b/perlio.c index 8f6947f..a3ff71d 100644 --- a/perlio.c +++ b/perlio.c @@ -4192,6 +4192,21 @@ typedef struct { * buffer */ } PerlIOCrlf; +/* Inherit the PERLIO_F_UTF8 flag from previous layer. + * Otherwise the :crlf layer would always revert back to + * raw mode. + */ +static void +S_inherit_utf8_flag(PerlIO *f) +{ + PerlIO *g = PerlIONext(f); + if (PerlIOValid(g)) { + if (PerlIOBase(g)->flags & PERLIO_F_UTF8) { + PerlIOBase(f)->flags |= PERLIO_F_UTF8; + } + } +} + IV PerlIOCrlf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab) { @@ -4209,17 +4224,19 @@ PerlIOCrlf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab) * any given moment at most one CRLF-capable layer being enabled * in the whole layer stack. */ PerlIO *g = PerlIONext(f); - while (g && *g) { + while (PerlIOValid(g)) { PerlIOl *b = PerlIOBase(g); if (b && b->tab == &PerlIO_crlf) { if (!(b->flags & PERLIO_F_CRLF)) b->flags |= PERLIO_F_CRLF; + S_inherit_utf8_flag(g); PerlIO_pop(aTHX_ f); return code; } g = PerlIONext(g); } } + S_inherit_utf8_flag(f); return code; } -- 2.7.4