(void)SvUPGRADE(sv, SVt_PV);
SvSCREAM_off(sv);
- SvPOK_only(sv); /* Validate pointer */
+
+ if (append) {
+ if (PerlIO_isutf8(fp)) {
+ if (!SvUTF8(sv)) {
+ sv_utf8_upgrade_nomg(sv);
+ sv_pos_u2b(sv,&append,0);
+ }
+ } else if (SvUTF8(sv)) {
+ SV *tsv = NEWSV(0,0);
+ sv_gets(tsv, fp, 0);
+ sv_utf8_upgrade_nomg(tsv);
+ SvCUR_set(sv,append);
+ sv_catsv(sv,tsv);
+ sv_free(tsv);
+ goto return_string_or_null;
+ }
+ }
+
+ SvPOK_only(sv);
+ if (PerlIO_isutf8(fp))
+ SvUTF8_on(sv);
if (PL_curcop == &PL_compiling) {
/* we always read code in line mode */
#endif
SvCUR_set(sv, bytesread += append);
buffer[bytesread] = '\0';
- goto check_utf8_and_return;
+ goto return_string_or_null;
}
else if (RsPARA(PL_rs)) {
rsptr = "\n\n";
}
}
-check_utf8_and_return:
- if (PerlIO_isutf8(fp))
- SvUTF8_on(sv);
- else
- SvUTF8_off(sv);
-
+return_string_or_null:
return (SvCUR(sv) - append) ? SvPVX(sv) : Nullch;
}
no utf8; # needed for use utf8 not griping about the raw octets
$| = 1;
-print "1..31\n";
+print "1..33\n";
open(F,"+>:utf8",'a');
print F chr(0x100).'£';
print $@ =~ /Wide character in print/ ? "ok 31\n" : "not ok 31\n";
}
+{
+ open F, ">:bytes","a"; print F "\xde"; close F;
+
+ open F, "<:bytes", "a";
+ my $b = chr 0x100;
+ $b .= <F>;
+ print $b eq chr(0x100).chr(0xde) ? "ok 32" : "not ok 32";
+ print " \#21395 '.= <>' utf8 vs. bytes\n";
+ close F;
+}
+
+{
+ open F, ">:utf8","a"; print F chr 0x100; close F;
+
+ open F, "<:utf8", "a";
+ my $b = "\xde";
+ $b .= <F>;
+ print $b eq chr(0xde).chr(0x100) ? "ok 33" : "not ok 33";
+ print " \#21395 '.= <>' bytes vs. utf8\n";
+ close F;
+}
+
# sysread() and syswrite() tested in lib/open.t since Fnctl is used
END {