}
use Config;
-use File::Spec::Functions;
-my $Is_MacOS = ($^O eq 'MacOS');
my $Is_VMSish = ($^O eq 'VMS');
if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
my $accurate_timestamps =
!($^O eq 'MSWin32' || $^O eq 'NetWare' ||
$^O eq 'dos' || $^O eq 'os2' ||
- $^O eq 'mint' || $^O eq 'cygwin' ||
- $^O eq 'amigaos' || $wd =~ m#$Config{afsroot}/# ||
- $Is_MacOS
+ $^O eq 'cygwin' || $^O eq 'amigaos' ||
+ $wd =~ m#$Config{afsroot}/#
);
if (defined &Win32::IsWinNT && Win32::IsWinNT()) {
my $skip_mode_checks =
$^O eq 'cygwin' && $ENV{CYGWIN} !~ /ntsec/;
-plan tests => 51;
+plan tests => 52;
+my $tmpdir = tempfile();
+my $tmpdir1 = tempfile();
if (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
- `rmdir /s /q tmp 2>nul`;
- `mkdir tmp`;
+ `rmdir /s /q $tmpdir 2>nul`;
+ `mkdir $tmpdir`;
}
elsif ($^O eq 'VMS') {
- `if f\$search("[.tmp]*.*") .nes. "" then delete/nolog/noconfirm [.tmp]*.*.*`;
- `if f\$search("tmp.dir") .nes. "" then set file/prot=o:rwed tmp.dir;`;
- `if f\$search("tmp.dir") .nes. "" then delete/nolog/noconfirm tmp.dir;`;
- `create/directory [.tmp]`;
-}
-elsif ($Is_MacOS) {
- rmdir "tmp"; mkdir "tmp";
+ `if f\$search("[.$tmpdir]*.*") .nes. "" then delete/nolog/noconfirm [.$tmpdir]*.*.*`;
+ `if f\$search("$tmpdir.dir") .nes. "" then set file/prot=o:rwed $tmpdir.dir;`;
+ `if f\$search("$tmpdir.dir") .nes. "" then delete/nolog/noconfirm $tmpdir.dir;`;
+ `create/directory [.$tmpdir]`;
}
else {
- `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`;
+ `rm -f $tmpdir 2>/dev/null; mkdir $tmpdir 2>/dev/null`;
}
-chdir catdir(curdir(), 'tmp');
+chdir $tmpdir;
`/bin/rm -rf a b c x` if -x '/bin/rm';
umask(022);
SKIP: {
- skip "bogus umask", 1 if ($^O eq 'MSWin32') || ($^O eq 'NetWare') || ($^O eq 'epoc') || $Is_MacOS;
+ skip "bogus umask", 1 if ($^O eq 'MSWin32') || ($^O eq 'NetWare') || ($^O eq 'epoc');
is((umask(0)&0777), 022, 'umask'),
}
close(FH);
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
- $blksize,$blocks);
+ $blksize,$blocks,$a_mode);
SKIP: {
skip("no link", 4) unless $has_link;
ok(link('a','b'), "link a b");
ok(link('b','c'), "link b c");
+ $a_mode = (stat('a'))[2];
+
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
$blksize,$blocks) = stat('c');
# if ($^O eq 'cygwin') { # new files on cygwin get rwx instead of rw-
# is($mode & 0777, 0777, "mode of triply-linked file");
# } else {
- is($mode & 0777, 0666, "mode of triply-linked file");
+ is(sprintf("0%o", $mode & 0777),
+ sprintf("0%o", $a_mode & 0777),
+ "mode of triply-linked file");
# }
}
}
skip "has fchown", 1 if ($Config{d_fchown} || "") eq "define";
open(my $fh, "<", "a");
eval { chown(0, 0, $fh); };
- like($@, qr/^The fchown function is unimplemented at/, "fchown is unimplemented");
+ like($@, qr/^The f?chown function is unimplemented at/, "fchown is unimplemented");
}
is(rename('a','b'), 1, "rename a b");
is( $atime, 500000001, 'atime' );
is( $mtime, 500000000 + $delta, 'mtime' );
}
- elsif ($^O eq 'beos') {
+ elsif ($^O eq 'beos' || $^O eq 'haiku') {
SKIP: {
skip "atime not updated", 1;
}
unlink("TEST$$");
}
-unlink "Iofs.tmp";
-open IOFSCOM, ">Iofs.tmp" or die "Could not write IOfs.tmp: $!";
+my $tmpfile = tempfile();
+open IOFSCOM, ">$tmpfile" or die "Could not write IOfs.tmp: $!";
print IOFSCOM 'helloworld';
close(IOFSCOM);
SKIP: {
# Check truncating a closed file.
- eval { truncate "Iofs.tmp", 5; };
+ eval { truncate $tmpfile, 5; };
skip("no truncate - $@", 8) if $@;
- is(-s "Iofs.tmp", 5, "truncation to five bytes");
+ is(-s $tmpfile, 5, "truncation to five bytes");
- truncate "Iofs.tmp", 0;
+ truncate $tmpfile, 0;
- ok(-z "Iofs.tmp", "truncation to zero bytes");
+ ok(-z $tmpfile, "truncation to zero bytes");
#these steps are necessary to check if file is really truncated
#On Win95, FH is updated, but file properties aren't
- open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp";
+ open(FH, ">$tmpfile") or die "Can't create $tmpfile";
print FH "x\n" x 200;
close FH;
# Check truncating an open file.
- open(FH, ">>Iofs.tmp") or die "Can't open Iofs.tmp for appending";
+ open(FH, ">>$tmpfile") or die "Can't open $tmpfile for appending";
binmode FH;
select FH;
}
if ($needs_fh_reopen) {
- close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
+ close (FH); open (FH, ">>$tmpfile") or die "Can't reopen $tmpfile";
}
SKIP: {
if ($^O eq 'vos') {
- skip ("# TODO - hit VOS bug posix-973 - cannot resize an open file below the current file pos.", 5);
+ skip ("# TODO - hit VOS bug posix-973 - cannot resize an open file below the current file pos.", 6);
}
- is(-s "Iofs.tmp", 200, "fh resize to 200 working (filename check)");
+ is(-s $tmpfile, 200, "fh resize to 200 working (filename check)");
ok(truncate(FH, 0), "fh resize to zero");
if ($needs_fh_reopen) {
- close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
+ close (FH); open (FH, ">>$tmpfile") or die "Can't reopen $tmpfile";
}
- ok(-z "Iofs.tmp", "fh resize to zero working (filename check)");
+ ok(-z $tmpfile, "fh resize to zero working (filename check)");
close FH;
- open(FH, ">>Iofs.tmp") or die "Can't open Iofs.tmp for appending";
+ open(FH, ">>$tmpfile") or die "Can't open $tmpfile for appending";
binmode FH;
select FH;
}
if ($needs_fh_reopen) {
- close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
+ close (FH); open (FH, ">>$tmpfile") or die "Can't reopen $tmpfile";
}
- is(-s "Iofs.tmp", 100, "fh resize by IO slot working");
+ is(-s $tmpfile, 100, "fh resize by IO slot working");
close FH;
+
+ my $n = "for_fs_dot_t$$";
+ open FH, ">$n" or die "open $n: $!";
+ print FH "bloh blah bla\n";
+ close FH or die "close $n: $!";
+ eval "truncate $n, 0; 1" or die;
+ ok !-z $n, 'truncate(word) does not fall back to file name';
+ unlink $n;
}
}
# check if rename() can be used to just change case of filename
SKIP: {
skip "Works in Cygwin only if check_case is set to relaxed", 1
- if $^O eq 'cygwin';
+ if ($ENV{'CYGWIN'} && ($ENV{'CYGWIN'} =~ /check_case:(?:adjust|strict)/));
- chdir './tmp';
+ chdir "./$tmpdir";
open(FH,'>x') || die "Can't create x";
close(FH);
rename('x', 'X');
# this works on win32 only, because fs isn't casesensitive
ok(-e 'X', "rename working");
- 1 while unlink 'X';
+ unlink_all 'X';
chdir $wd || die "Can't cd back to $wd";
}
# check if rename() works on directories
if ($^O eq 'VMS') {
# must have delete access to rename a directory
- `set file tmp.dir/protection=o:d`;
- ok(rename('tmp.dir', 'tmp1.dir'), "rename on directories") ||
+ `set file $tmpdir.dir/protection=o:d`;
+ ok(rename("$tmpdir.dir", "$tmpdir1.dir"), "rename on directories") ||
print "# errno: $!\n";
}
else {
- ok(rename('tmp', 'tmp1'), "rename on directories");
+ ok(rename($tmpdir, $tmpdir1), "rename on directories");
}
-ok(-d 'tmp1', "rename on directories working");
+ok(-d $tmpdir1, "rename on directories working");
{
# Change 26011: Re: A surprising segfault
ok(1, "extend sp in pp_chown");
}
-# need to remove 'tmp' if rename() in test 28 failed!
-END { rmdir 'tmp1'; rmdir 'tmp'; 1 while unlink "Iofs.tmp"; }
+# need to remove $tmpdir if rename() in test 28 failed!
+END { rmdir $tmpdir1; rmdir $tmpdir; }