# then create a file via perlio without autoflush
- TODO:{
- todo_skip "$e: !perlio_ok", 1 unless perlio_ok($e);
+# TODO:{
+# local $TODO = "perlio broken";
+# todo_skip "$e: !perlio_ok", 1 unless perlio_ok($e);
open $fh, ">:encoding($e)", $pfile or die "$sfile : $!";
$fh->autoflush(0);
print $fh $utext;
close $fh;
ok(compare($sfile, $pfile) == 0 => ">:encoding($e)");
- }
+# }
# this time print line by line.
# works even for ISO-2022!
close $fh;
is(compare($sfile, $pfile), 0 => ">:encoding($e); line-by-line");
- TODO:{
- todo_skip "$e: !perlio_ok", 2 unless perlio_ok($e);
+# TODO:{
+# local $TODO = "perlio broken";
+# todo_skip "$e: !perlio_ok", 2 unless perlio_ok($e);
open $fh, "<:encoding($e)", $pfile or die "$pfile : $!";
$fh->autoflush(0);
my $dtext = join('' => <$fh>);
}
close $fh;
ok($utext eq $dtext, "<:encoding($e); line-by-line");
- }
+# }
$DEBUG or unlink ($sfile, $pfile);
}
#define NEEDS_LINES 1
#if 0
-#define OUR_ENCODE_FB "Encode::FB_DEFAULT"
+#define OUR_ENCODE_FB "Encode::FB_PERLQQ"
#else
#define OUR_ENCODE_FB "Encode::FB_QUIET"
#endif
}
}
PerlIOBase(f)->flags |= PERLIO_F_UTF8;
- if (e->flags & NEEDS_LINES) {
- PerlIOBase(f)->flags |= PERLIO_F_LINEBUF;
- }
}
e->chk = newSVsv(get_sv("PerlIO::encoding::check",0));
SSize_t
PerlIOEncode_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count)
{
- SSize_t size = PerlIOBuf_write(aTHX_ f, vbuf, count);
PerlIOEncode *e = PerlIOSelf(f, PerlIOEncode);
if (e->flags & NEEDS_LINES) {
+ SSize_t done = 0;
+ const char *ptr = (const char *) vbuf;
+ const char *end = ptr+count;
+ while (ptr < end) {
+ const char *nl = ptr;
+ while (nl < end && *nl++ != '\n') /* empty body */;
+ done = PerlIOBuf_write(aTHX_ f, ptr, nl-ptr);
+ if (done != nl-ptr) {
+ if (done > 0) {
+ ptr += done;
+ }
+ break;
+ }
+ ptr += done;
+ if (ptr[-1] == '\n') {
+ if (PerlIOEncode_flush(aTHX_ f) != 0) {
+ break;
+ }
+ }
+ }
+ return (SSize_t) (ptr - (const char *) vbuf);
+ }
+ else {
+ return PerlIOBuf_write(aTHX_ f, vbuf, count);
}
- return size;
}
PerlIO_funcs PerlIO_encode = {