13 $Is_Dosish = ($^O eq 'MSWin32' or
14 $^O eq 'os2' or $^O eq 'cygwin');
16 open($TST, 'harness') || (die "Can't open harness");
17 binmode $TST if $Is_Dosish;
18 ok(!eof(TST), "eof is false after open() non-empty file");
27 is($x, 1, "only one eof is in the file");
31 ok(eof, "tell() doesn't change current state of eof");
33 ok(seek($TST,0,0), "set current position at beginning of the file");
35 ok(!eof, "reset at beginning of file clears eof flag");
37 is($firstline, <TST>, "first line is the same after open() and after seek()");
39 is($secondpos, tell, "position is the same after reading the first line");
41 ok(seek(TST,0,1), "move current position on +0");
43 ok(!eof($TST), "it doesn't set eof flag");
45 is($secondpos, tell, "it doesn't change tell position");
47 ok(seek(TST,0,2), "move current position at the end of the file");
49 is($lastpos, tell, "the position is the same as after reading whole file line by line");
51 ok(eof, "it sets eof flag");
53 ok($., "current line number \$. is not null");
56 open(OTHER, 'harness') || (die "Can't open harness: $!");
57 binmode OTHER if ($^O eq 'MSWin32');
62 ok($., "open() doesn't change filehandler for \$.");
65 ok(!$., "tell() does change filehandler for \$.");
69 is ($., 6, "reading of one line adds +1 to current line number \$.");
72 is($., $curline, "the 'local' correctly restores old value of filehandler for \$. when goes out of scope");
78 is($., 7, "reading of one line inside 'local' change filehandler for \$.");
81 is($., $curline, "the 'local' correctly restores old value of filehandler for \$. when goes out of scope");
87 is($., 7, "tell() inside 'local' change filehandler for \$.");
93 is(tell(OTHER), -1, "tell() for closed file returns -1");
96 no warnings 'unopened';
97 # this must be a handle that has never been opened
98 is(tell(UNOPENED), -1, "tell() for unopened file returns -1");
101 # ftell(STDIN) (or any std streams) is undefined, it can return -1 or
102 # something else. ftell() on pipes, fifos, and sockets is defined to
105 my $written = tempfile();
108 open($tst,">$written") || die "Cannot open $written:$!";
109 binmode $tst if $Is_Dosish;
111 is(tell($tst), 0, "tell() for new file returns 0");
115 is(tell($tst), 5, 'tell() after writing "fred\n" returns 5');
119 is(tell($tst), 10, 'tell() after writing "more\n" returns 10');
123 open($tst,"+>>$written") || die "Cannot open $written:$!";
124 binmode $tst if $Is_Dosish;
128 # :stdio does not pass these so ignore them for now
130 is(tell($tst), 0, 'tell() for open mode "+>>" returns 0');
134 is($line, "fred\n", 'check first line in mode "+>>"');
136 is(tell($tst), 5, "check tell() afrer reading first line");
142 ok( tell($tst) == 15 ||
144 'check tell() after writing "xxxx\n"'); # unset PERLIO or PERLIO=stdio (e.g. HP-UX, Solaris)
148 open($tst,">$written") || die "Cannot open $written:$!";
151 open($tst,">>$written") || die "Cannot open $written:$!";
153 # This test makes a questionable assumption that the file pointer will
154 # be at eof after opening a file but before seeking, reading, or writing.
155 # The POSIX standard is vague on this point.
156 # Cygwin and VOS differ from other implementations.
158 if (tell ($tst) == 6) {
159 pass("check tell() after writing in mode '>>'");
162 if (($^O eq "cygwin") && (&PerlIO::get_layers($tst) eq 'stdio')) {
163 fail "# TODO: file pointer not at eof";
165 elsif ($^O eq "vos") {
166 fail "# TODO: Hit bug posix-2056. file pointer not at eof";
169 fail "file pointer not at eof";
176 $fh = *FH; # coercible glob
177 is(tell($fh), 0, "tell on coercible glob");
178 is(tell, 0, "argless tell after tell \$coercible");
180 is(tell, 0, "argless tell after tell *\$coercible");
182 is(tell, 0, "argless tell after eof \$coercible");
184 is(tell, 0, "argless tell after eof *\$coercible");
186 is(tell, 0, "argless tell after seek \$coercible...");
188 is(tell, 0, "argless tell after seek *\$coercible...");
192 fresh_perl_is(<<'EOI', 'ok', {}, 'eof with no ${^LAST_FH}');