Make PerlIO_getpos() to behave like fgetpos() on return.
[p5sagit/p5-mst-13.2.git] / t / lib / io_xs.t
CommitLineData
61f2b451 1#!./perl
61f2b451 2
3BEGIN {
7a4c00b4 4 unless(grep /blib/, @INC) {
5 chdir 't' if -d 't';
20822f61 6 @INC = '../lib';
7a4c00b4 7 }
8}
9
10use Config;
11
12BEGIN {
13 if(-d "lib" && -f "TEST") {
14 if ($Config{'extensions'} !~ /\bIO\b/ && $^O ne 'VMS') {
15 print "1..0\n";
16 exit 0;
17 }
61f2b451 18 }
19}
20
21use IO::File;
22use IO::Seekable;
23
a6a714bd 24print "1..6\n";
fefb1980 25
61f2b451 26$x = new_tmpfile IO::File or print "not ";
27print "ok 1\n";
28print $x "ok 2\n";
29$x->seek(0,SEEK_SET);
30print <$x>;
fefb1980 31
32$x->seek(0,SEEK_SET);
33print $x "not ok 3\n";
34$p = $x->getpos;
35print $x "ok 3\n";
36$x->flush;
37$x->setpos($p);
38print scalar <$x>;
39
40$! = 0;
41$x->setpos(undef);
42print $! ? "ok 4 # $!\n" : "not ok 4\n";
a6a714bd 43
44# These shenanigans are intended to make a perl IO pointing to C FILE *
45# (or equivalent) on a closed file handle. Something that will fail fgetops()
46# Might be easier to use STDIN if (-t STDIN || -P STDIN) if ttys/pipes on
47# all platforms fail to fgetpos()
48$fn = $x->fileno();
49$y = new IO::File;
50if ($y->fdopen ($fn, "r")) {
51 print "ok 5\n";
52 $x->close() or die $!;
53 $!=0;
54 $p = $y->getpos;
55 if (defined $p) {
56 print "not ok 6 # closed handle returned defined position, \$!='$!'\n";
57 } else {
58 print "ok 6 # $!\n";
59 }
60} else {
61 print "not ok 5 # failed to duplicated file number $fd\n", "not ok 6\n";
62}