6 push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS';
7 unless (find PerlIO::Layer 'perlio') {
8 print "1..0 # Skip: not perlio\n";
18 my $russki = "koi8r$$";
20 if (open(GRK, ">$grk")) {
21 binmode(GRK, ":bytes");
22 # alpha beta gamma in ISO 8859-7
23 print GRK "\xe1\xe2\xe3";
24 close GRK or die "Could not close: $!";
29 open(my $i,'<:encoding(iso-8859-7)',$grk);
31 open(my $o,'>:utf8',$utf);
33 print $o readline($i);
35 close($o) or die "Could not close: $!";
39 if (open(UTF, "<$utf")) {
40 binmode(UTF, ":bytes");
41 if (ord('A') == 193) { # EBCDIC
42 # alpha beta gamma in UTF-EBCDIC Unicode (0x3b1 0x3b2 0x3b3)
43 print "not " unless <UTF> eq "\xb4\x58\xb4\x59\xb4\x62";
45 # alpha beta gamma in UTF-8 Unicode (0x3b1 0x3b2 0x3b3)
46 print "not " unless <UTF> eq "\xce\xb1\xce\xb2\xce\xb3";
54 open(my $i,'<:utf8',$utf);
56 open(my $o,'>:encoding(iso-8859-7)',$grk);
58 print $o readline($i);
60 close($o) or die "Could not close: $!";
64 if (open(GRK, "<$grk")) {
65 binmode(GRK, ":bytes");
66 print "not " unless <GRK> eq "\xe1\xe2\xe3";
71 $SIG{__WARN__} = sub {$warn = $_[0]};
73 if (open(FAIL, ">:encoding(NoneSuch)", $fail1)) {
74 print "not ok 9 # Open should fail\n";
79 print "not ok 10 # warning is undef\n";
80 } elsif ($warn =~ /^Cannot find encoding "NoneSuch" at/) {
83 print "not ok 10 # warning is '$warn'";
86 if (open(RUSSKI, ">$russki")) {
87 print RUSSKI "\x3c\x3f\x78";
88 close RUSSKI or die "Could not close: $!";
89 open(RUSSKI, "$russki");
90 binmode(RUSSKI, ":raw");
92 read(RUSSKI, $buf1, 1);
94 binmode(RUSSKI, ":encoding(koi8-r)");
96 read(RUSSKI, $buf2, 1);
97 my $offset = tell(RUSSKI);
98 if (ord($buf1) == 0x3c &&
99 ord($buf2) == (ord('A') == 193) ? 0x6f : 0x3f &&
103 printf "not ok 11 # [%s] [%s] %d\n",
104 join(" ", unpack("H*", $buf1)),
105 join(" ", unpack("H*", $buf2)), $offset;
109 print "not ok 11 # open failed: $!\n";
113 unlink($grk, $utf, $fail1, $russki);