From: Nick Ing-Simmons Date: Sun, 11 Aug 2002 10:25:15 +0000 (+0000) Subject: Fix for [perl #15986] tell/seek misbehave for :crlf X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e949e37c57a7b8894b837a34a436233508daf2e1;p=p5sagit%2Fp5-mst-13.2.git Fix for [perl #15986] tell/seek misbehave for :crlf Test from "Vadim Konovalov" fix by Nick I-S based on study of problem based on Vadim's analysis. p4raw-id: //depot/perlio@17709 --- diff --git a/perlio.c b/perlio.c index 11f600f..ea36d80 100644 --- a/perlio.c +++ b/perlio.c @@ -3839,13 +3839,16 @@ PerlIOCrlf_get_cnt(pTHX_ PerlIO *f) b->ptr++; /* say we have read it as far as * flush() is concerned */ b->buf++; /* Leave space in front of buffer */ + /* Note as we have moved buf up flush's + posn += ptr-buf + will naturally make posn point at CR + */ b->bufsiz--; /* Buffer is thus smaller */ code = PerlIO_fill(f); /* Fetch some more */ b->bufsiz++; /* Restore size for next time */ b->buf--; /* Point at space */ b->ptr = nl = b->buf; /* Which is what we hand * off */ - b->posn--; /* Buffer starts here */ *nl = 0xd; /* Fill in the CR */ if (code == 0) goto test; /* fill() call worked */ diff --git a/t/io/crlf.t b/t/io/crlf.t index 08ab4fe..484596b 100644 --- a/t/io/crlf.t +++ b/t/io/crlf.t @@ -15,7 +15,7 @@ END { } if (find PerlIO::Layer 'perlio') { - plan(tests => 7); + plan(tests => 8); ok(open(FOO,">:crlf",$file)); ok(print FOO 'a'.((('a' x 14).qq{\n}) x 2000) || close(FOO)); ok(open(FOO,"<:crlf",$file)); @@ -30,6 +30,18 @@ if (find PerlIO::Layer 'perlio') { { local $/; $text = } is(count_chars($text, "\015\012"), 2000); + { + my $fcontents = join "", map {"$_\r\n"} "a".."zzz"; + open my $fh, "<:crlf", \$fcontents; + local $/ = "xxx"; + local $_ = <$fh>; + my $pos = tell $fh; # pos must be behind "xxx", before "\nyyy\n" + seek $fh, $pos, 0; + $/ = "\n"; + $s = <$fh>.<$fh>; + ok($s eq "\nxxy\n"); + } + ok(close(FOO)); } else {