5 @INC = '../lib' if -f '../lib/Carp.pm';
8 if ($^O =~ /^(MSWin32|os2|NetWare|dos)$/) {
12 print "1..0 # skipped: not a dosish system\n";
16 use Fcntl qw(:DEFAULT :seek);
17 my $tmpf = "sysioc.tmp";
22 # default read/write modes should be text
24 sysopen(my $F, $tmpf, O_CREAT|O_RDWR|O_TRUNC) or die "Can't open $tmpf: $!";
25 $n = syswrite($F, "zyx\n");
26 print "not " unless $n == 4;
29 # must be flushed and closed here
30 print "not " if (-s $tmpf) != 5; # should be "zyx\r\n"
34 sysopen(my $F, $tmpf, O_RDONLY) or die "Can't open $tmpf: $!";
35 $n = sysread($F, $v, 4);
36 print "not " unless $n == 4;
38 print "not " unless $v eq "zyx\n";
40 $n = sysread($F, $v, 10);
41 print "not " unless $n == 0; # eof
43 $n = sysseek($F, 0, SEEK_SET);
44 print "not " unless $n == 0;
46 $n = sysread($F, $v, 10);
47 print "not " unless $n == 4; # short read
49 print "not " unless $v eq "zyx\n";
53 # reading in binmode should see real contents
55 sysopen(my $F, $tmpf, O_RDONLY|O_BINARY) or die "Can't open $tmpf: $!";
56 $n = sysread($F, $v, 5);
57 print "not " unless $n == 5;
59 print "not " unless $v eq "zyx\r\n";
61 $n = sysread($F, $v, 10);
62 print "not " unless $n == 0; # eof
64 $n = sysseek($F, 0, SEEK_SET);
65 print "not " unless $n == 0;
67 $n = sysread($F, $v, 10);
68 print "not " unless $n == 5; # short read
70 print "not " unless $v eq "zyx\r\n";
76 sysopen(my $F, $tmpf, O_CREAT|O_RDWR|O_TRUNC|O_BINARY) or die "Can't open $tmpf: $!";
77 $n = syswrite($F, "zyx\r\n\cZpqr");
78 print "not " unless $n == 9;
81 # must be flushed and closed here
82 print "not " if (-s $tmpf) != 9; # should be "zyx\r\n\cZpqr"
86 sysopen(my $F, $tmpf, O_RDONLY) or die "Can't open $tmpf: $!";
87 $n = sysread($F, $v, 4);
88 print "not " unless $n == 4;
90 print "not " unless $v eq "zyx\n";
92 $n = sysread($F, $v, 10); # eof
93 print "not " unless $n == 0;
95 $n = sysseek($F, 0, SEEK_SET);
96 print "not " unless $n == 0;
98 $n = sysread($F, $v, 10);
99 print "not " unless $n == 4; # short read
101 print "not " unless $v eq "zyx\n";
103 $n = sysread($F, $v, 10); # eof
104 print "not " unless $n == 0;
108 # reading in binmode should see real contents
110 sysopen(my $F, $tmpf, O_RDONLY|O_BINARY) or die "Can't open $tmpf: $!";
111 $n = sysread($F, $v, 9);
112 print "not " unless $n == 9;
114 print "not " unless $v eq "zyx\r\n\cZpqr";