xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/io/fs.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateBEGIN {
4*0Sstevel@tonic-gate    chdir 't' if -d 't';
5*0Sstevel@tonic-gate    @INC = '../lib';
6*0Sstevel@tonic-gate    require "./test.pl";
7*0Sstevel@tonic-gate}
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gateuse Config;
10*0Sstevel@tonic-gateuse File::Spec::Functions;
11*0Sstevel@tonic-gate
12*0Sstevel@tonic-gatemy $Is_MacOS  = ($^O eq 'MacOS');
13*0Sstevel@tonic-gatemy $Is_VMSish = ($^O eq 'VMS');
14*0Sstevel@tonic-gate
15*0Sstevel@tonic-gateif (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
16*0Sstevel@tonic-gate    $wd = `cd`;
17*0Sstevel@tonic-gate} elsif ($^O eq 'VMS') {
18*0Sstevel@tonic-gate    $wd = `show default`;
19*0Sstevel@tonic-gate} else {
20*0Sstevel@tonic-gate    $wd = `pwd`;
21*0Sstevel@tonic-gate}
22*0Sstevel@tonic-gatechomp($wd);
23*0Sstevel@tonic-gate
24*0Sstevel@tonic-gatemy $has_link            = $Config{d_link};
25*0Sstevel@tonic-gatemy $accurate_timestamps =
26*0Sstevel@tonic-gate    !($^O eq 'MSWin32' || $^O eq 'NetWare' ||
27*0Sstevel@tonic-gate      $^O eq 'dos'     || $^O eq 'os2'     ||
28*0Sstevel@tonic-gate      $^O eq 'mint'    || $^O eq 'cygwin'  ||
29*0Sstevel@tonic-gate      $^O eq 'amigaos' || $wd =~ m#$Config{afsroot}/# ||
30*0Sstevel@tonic-gate      $Is_MacOS
31*0Sstevel@tonic-gate     );
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gateif (defined &Win32::IsWinNT && Win32::IsWinNT()) {
34*0Sstevel@tonic-gate    if (Win32::FsType() eq 'NTFS') {
35*0Sstevel@tonic-gate        $has_link            = 1;
36*0Sstevel@tonic-gate        $accurate_timestamps = 1;
37*0Sstevel@tonic-gate    }
38*0Sstevel@tonic-gate}
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gatemy $needs_fh_reopen =
41*0Sstevel@tonic-gate    $^O eq 'dos'
42*0Sstevel@tonic-gate    # Not needed on HPFS, but needed on HPFS386 ?!
43*0Sstevel@tonic-gate    || $^O eq 'os2';
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gate$needs_fh_reopen = 1 if (defined &Win32::IsWin95 && Win32::IsWin95());
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gatemy $skip_mode_checks =
48*0Sstevel@tonic-gate    $^O eq 'cygwin' && $ENV{CYGWIN} !~ /ntsec/;
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gateplan tests => 34;
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gateif (($^O eq 'MSWin32') || ($^O eq 'NetWare')) {
54*0Sstevel@tonic-gate    `rmdir /s /q tmp 2>nul`;
55*0Sstevel@tonic-gate    `mkdir tmp`;
56*0Sstevel@tonic-gate}
57*0Sstevel@tonic-gateelsif ($^O eq 'VMS') {
58*0Sstevel@tonic-gate    `if f\$search("[.tmp]*.*") .nes. "" then delete/nolog/noconfirm [.tmp]*.*.*`;
59*0Sstevel@tonic-gate    `if f\$search("tmp.dir") .nes. "" then delete/nolog/noconfirm tmp.dir;`;
60*0Sstevel@tonic-gate    `create/directory [.tmp]`;
61*0Sstevel@tonic-gate}
62*0Sstevel@tonic-gateelsif ($Is_MacOS) {
63*0Sstevel@tonic-gate    rmdir "tmp"; mkdir "tmp";
64*0Sstevel@tonic-gate}
65*0Sstevel@tonic-gateelse {
66*0Sstevel@tonic-gate    `rm -f tmp 2>/dev/null; mkdir tmp 2>/dev/null`;
67*0Sstevel@tonic-gate}
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gatechdir catdir(curdir(), 'tmp');
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gate`/bin/rm -rf a b c x` if -x '/bin/rm';
72*0Sstevel@tonic-gate
73*0Sstevel@tonic-gateumask(022);
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gateSKIP: {
76*0Sstevel@tonic-gate    skip "bogus umask", 1 if ($^O eq 'MSWin32') || ($^O eq 'NetWare') || ($^O eq 'epoc') || $Is_MacOS;
77*0Sstevel@tonic-gate
78*0Sstevel@tonic-gate    is((umask(0)&0777), 022, 'umask'),
79*0Sstevel@tonic-gate}
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gateopen(fh,'>x') || die "Can't create x";
82*0Sstevel@tonic-gateclose(fh);
83*0Sstevel@tonic-gateopen(fh,'>a') || die "Can't create a";
84*0Sstevel@tonic-gateclose(fh);
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gatemy ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
87*0Sstevel@tonic-gate    $blksize,$blocks);
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gateSKIP: {
90*0Sstevel@tonic-gate    skip("no link", 4) unless $has_link;
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate    ok(link('a','b'), "link a b");
93*0Sstevel@tonic-gate    ok(link('b','c'), "link b c");
94*0Sstevel@tonic-gate
95*0Sstevel@tonic-gate    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
96*0Sstevel@tonic-gate     $blksize,$blocks) = stat('c');
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gate    SKIP: {
99*0Sstevel@tonic-gate        skip "no nlink", 1 if $Config{dont_use_nlink};
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate        is($nlink, 3, "link count of triply-linked file");
102*0Sstevel@tonic-gate    }
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gate    SKIP: {
105*0Sstevel@tonic-gate        skip "hard links not that hard in $^O", 1 if $^O eq 'amigaos';
106*0Sstevel@tonic-gate	skip "no mode checks", 1 if $skip_mode_checks;
107*0Sstevel@tonic-gate
108*0Sstevel@tonic-gate#      if ($^O eq 'cygwin') { # new files on cygwin get rwx instead of rw-
109*0Sstevel@tonic-gate#          is($mode & 0777, 0777, "mode of triply-linked file");
110*0Sstevel@tonic-gate#      } else {
111*0Sstevel@tonic-gate            is($mode & 0777, 0666, "mode of triply-linked file");
112*0Sstevel@tonic-gate#      }
113*0Sstevel@tonic-gate    }
114*0Sstevel@tonic-gate}
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gate$newmode = (($^O eq 'MSWin32') || ($^O eq 'NetWare')) ? 0444 : 0777;
117*0Sstevel@tonic-gate
118*0Sstevel@tonic-gateis(chmod($newmode,'a'), 1, "chmod succeeding");
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gateSKIP: {
121*0Sstevel@tonic-gate    skip("no link", 7) unless $has_link;
122*0Sstevel@tonic-gate
123*0Sstevel@tonic-gate    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
124*0Sstevel@tonic-gate     $blksize,$blocks) = stat('c');
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate    SKIP: {
127*0Sstevel@tonic-gate	skip "no mode checks", 1 if $skip_mode_checks;
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate        is($mode & 0777, $newmode, "chmod going through");
130*0Sstevel@tonic-gate    }
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gate    $newmode = 0700;
133*0Sstevel@tonic-gate    chmod 0444, 'x';
134*0Sstevel@tonic-gate    $newmode = 0666;
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gate    is(chmod($newmode,'c','x'), 2, "chmod two files");
137*0Sstevel@tonic-gate
138*0Sstevel@tonic-gate    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
139*0Sstevel@tonic-gate     $blksize,$blocks) = stat('c');
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate    SKIP: {
142*0Sstevel@tonic-gate	skip "no mode checks", 1 if $skip_mode_checks;
143*0Sstevel@tonic-gate
144*0Sstevel@tonic-gate        is($mode & 0777, $newmode, "chmod going through to c");
145*0Sstevel@tonic-gate    }
146*0Sstevel@tonic-gate
147*0Sstevel@tonic-gate    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
148*0Sstevel@tonic-gate     $blksize,$blocks) = stat('x');
149*0Sstevel@tonic-gate
150*0Sstevel@tonic-gate    SKIP: {
151*0Sstevel@tonic-gate	skip "no mode checks", 1 if $skip_mode_checks;
152*0Sstevel@tonic-gate
153*0Sstevel@tonic-gate        is($mode & 0777, $newmode, "chmod going through to x");
154*0Sstevel@tonic-gate    }
155*0Sstevel@tonic-gate
156*0Sstevel@tonic-gate    is(unlink('b','x'), 2, "unlink two files");
157*0Sstevel@tonic-gate
158*0Sstevel@tonic-gate    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
159*0Sstevel@tonic-gate     $blksize,$blocks) = stat('b');
160*0Sstevel@tonic-gate
161*0Sstevel@tonic-gate    is($ino, undef, "ino of removed file b should be undef");
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
164*0Sstevel@tonic-gate     $blksize,$blocks) = stat('x');
165*0Sstevel@tonic-gate
166*0Sstevel@tonic-gate    is($ino, undef, "ino of removed file x should be undef");
167*0Sstevel@tonic-gate}
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gateis(rename('a','b'), 1, "rename a b");
170*0Sstevel@tonic-gate
171*0Sstevel@tonic-gate($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
172*0Sstevel@tonic-gate $blksize,$blocks) = stat('a');
173*0Sstevel@tonic-gate
174*0Sstevel@tonic-gateis($ino, undef, "ino of renamed file a should be undef");
175*0Sstevel@tonic-gate
176*0Sstevel@tonic-gate$delta = $accurate_timestamps ? 1 : 2;	# Granularity of time on the filesystem
177*0Sstevel@tonic-gatechmod 0777, 'b';
178*0Sstevel@tonic-gate$foo = (utime 500000000,500000000 + $delta,'b');
179*0Sstevel@tonic-gate
180*0Sstevel@tonic-gateis($foo, 1, "utime");
181*0Sstevel@tonic-gate
182*0Sstevel@tonic-gate($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
183*0Sstevel@tonic-gate    $blksize,$blocks) = stat('b');
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gateSKIP: {
186*0Sstevel@tonic-gate    skip "bogus inode num", 1 if ($^O eq 'MSWin32') || ($^O eq 'NetWare');
187*0Sstevel@tonic-gate
188*0Sstevel@tonic-gate    ok($ino,    'non-zero inode num');
189*0Sstevel@tonic-gate}
190*0Sstevel@tonic-gate
191*0Sstevel@tonic-gateSKIP: {
192*0Sstevel@tonic-gate    skip "filesystem atime/mtime granularity too low", 2
193*0Sstevel@tonic-gate      unless $accurate_timestamps;
194*0Sstevel@tonic-gate
195*0Sstevel@tonic-gate    print "# atime - $atime  mtime - $mtime  delta - $delta\n";
196*0Sstevel@tonic-gate    if($atime == 500000000 && $mtime == 500000000 + $delta) {
197*0Sstevel@tonic-gate        pass('atime');
198*0Sstevel@tonic-gate        pass('mtime');
199*0Sstevel@tonic-gate    }
200*0Sstevel@tonic-gate    else {
201*0Sstevel@tonic-gate        if ($^O =~ /\blinux\b/i) {
202*0Sstevel@tonic-gate            print "# Maybe stat() cannot get the correct atime, ".
203*0Sstevel@tonic-gate                  "as happens via NFS on linux?\n";
204*0Sstevel@tonic-gate            $foo = (utime 400000000,500000000 + 2*$delta,'b');
205*0Sstevel@tonic-gate            my ($new_atime, $new_mtime) = (stat('b'))[8,9];
206*0Sstevel@tonic-gate            print "# newatime - $new_atime  nemtime - $new_mtime\n";
207*0Sstevel@tonic-gate            if ($new_atime == $atime && $new_mtime - $mtime == $delta) {
208*0Sstevel@tonic-gate                pass("atime - accounted for possible NFS/glibc2.2 bug on linux");
209*0Sstevel@tonic-gate                pass("mtime - accounted for possible NFS/glibc2.2 bug on linux");
210*0Sstevel@tonic-gate            }
211*0Sstevel@tonic-gate            else {
212*0Sstevel@tonic-gate                fail("atime - $atime/$new_atime $mtime/$new_mtime");
213*0Sstevel@tonic-gate                fail("mtime - $atime/$new_atime $mtime/$new_mtime");
214*0Sstevel@tonic-gate            }
215*0Sstevel@tonic-gate        }
216*0Sstevel@tonic-gate        elsif ($^O eq 'VMS') {
217*0Sstevel@tonic-gate            # why is this 1 second off?
218*0Sstevel@tonic-gate            is( $atime, 500000001,          'atime' );
219*0Sstevel@tonic-gate            is( $mtime, 500000000 + $delta, 'mtime' );
220*0Sstevel@tonic-gate        }
221*0Sstevel@tonic-gate        elsif ($^O eq 'beos') {
222*0Sstevel@tonic-gate            SKIP: { skip "atime not updated", 1; }
223*0Sstevel@tonic-gate            is($mtime, 500000001, 'mtime');
224*0Sstevel@tonic-gate        }
225*0Sstevel@tonic-gate        else {
226*0Sstevel@tonic-gate            fail("atime");
227*0Sstevel@tonic-gate            fail("mtime");
228*0Sstevel@tonic-gate        }
229*0Sstevel@tonic-gate    }
230*0Sstevel@tonic-gate}
231*0Sstevel@tonic-gate
232*0Sstevel@tonic-gateis(unlink('b'), 1, "unlink b");
233*0Sstevel@tonic-gate
234*0Sstevel@tonic-gate($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
235*0Sstevel@tonic-gate    $blksize,$blocks) = stat('b');
236*0Sstevel@tonic-gateis($ino, undef, "ino of unlinked file b should be undef");
237*0Sstevel@tonic-gateunlink 'c';
238*0Sstevel@tonic-gate
239*0Sstevel@tonic-gatechdir $wd || die "Can't cd back to $wd";
240*0Sstevel@tonic-gate
241*0Sstevel@tonic-gate# Yet another way to look for links (perhaps those that cannot be
242*0Sstevel@tonic-gate# created by perl?).  Hopefully there is an ls utility in your
243*0Sstevel@tonic-gate# %PATH%. N.B. that $^O is 'cygwin' on Cygwin.
244*0Sstevel@tonic-gate
245*0Sstevel@tonic-gateSKIP: {
246*0Sstevel@tonic-gate    skip "Win32/Netware specific test", 2
247*0Sstevel@tonic-gate      unless ($^O eq 'MSWin32') || ($^O eq 'NetWare');
248*0Sstevel@tonic-gate    skip "No symbolic links found to test with", 2
249*0Sstevel@tonic-gate      unless  `ls -l perl 2>nul` =~ /^l.*->/;
250*0Sstevel@tonic-gate
251*0Sstevel@tonic-gate    system("cp TEST TEST$$");
252*0Sstevel@tonic-gate    # we have to copy because e.g. GNU grep gets huffy if we have
253*0Sstevel@tonic-gate    # a symlink forest to another disk (it complains about too many
254*0Sstevel@tonic-gate    # levels of symbolic links, even if we have only two)
255*0Sstevel@tonic-gate    is(symlink("TEST$$","c"), 1, "symlink");
256*0Sstevel@tonic-gate    $foo = `grep perl c 2>&1`;
257*0Sstevel@tonic-gate    ok($foo, "found perl in c");
258*0Sstevel@tonic-gate    unlink 'c';
259*0Sstevel@tonic-gate    unlink("TEST$$");
260*0Sstevel@tonic-gate}
261*0Sstevel@tonic-gate
262*0Sstevel@tonic-gateunlink "Iofs.tmp";
263*0Sstevel@tonic-gateopen IOFSCOM, ">Iofs.tmp" or die "Could not write IOfs.tmp: $!";
264*0Sstevel@tonic-gateprint IOFSCOM 'helloworld';
265*0Sstevel@tonic-gateclose(IOFSCOM);
266*0Sstevel@tonic-gate
267*0Sstevel@tonic-gate# TODO: pp_truncate needs to be taught about F_CHSIZE and F_FREESP,
268*0Sstevel@tonic-gate# as per UNIX FAQ.
269*0Sstevel@tonic-gate
270*0Sstevel@tonic-gateSKIP: {
271*0Sstevel@tonic-gate# Check truncating a closed file.
272*0Sstevel@tonic-gate    eval { truncate "Iofs.tmp", 5; };
273*0Sstevel@tonic-gate
274*0Sstevel@tonic-gate    skip("no truncate - $@", 8) if $@;
275*0Sstevel@tonic-gate
276*0Sstevel@tonic-gate    is(-s "Iofs.tmp", 5, "truncation to five bytes");
277*0Sstevel@tonic-gate
278*0Sstevel@tonic-gate    truncate "Iofs.tmp", 0;
279*0Sstevel@tonic-gate
280*0Sstevel@tonic-gate    ok(-z "Iofs.tmp",    "truncation to zero bytes");
281*0Sstevel@tonic-gate
282*0Sstevel@tonic-gate#these steps are necessary to check if file is really truncated
283*0Sstevel@tonic-gate#On Win95, FH is updated, but file properties aren't
284*0Sstevel@tonic-gate    open(FH, ">Iofs.tmp") or die "Can't create Iofs.tmp";
285*0Sstevel@tonic-gate    print FH "x\n" x 200;
286*0Sstevel@tonic-gate    close FH;
287*0Sstevel@tonic-gate
288*0Sstevel@tonic-gate# Check truncating an open file.
289*0Sstevel@tonic-gate    open(FH, ">>Iofs.tmp") or die "Can't open Iofs.tmp for appending";
290*0Sstevel@tonic-gate
291*0Sstevel@tonic-gate    binmode FH;
292*0Sstevel@tonic-gate    select FH;
293*0Sstevel@tonic-gate    $| = 1;
294*0Sstevel@tonic-gate    select STDOUT;
295*0Sstevel@tonic-gate
296*0Sstevel@tonic-gate    {
297*0Sstevel@tonic-gate	use strict;
298*0Sstevel@tonic-gate	print FH "x\n" x 200;
299*0Sstevel@tonic-gate	ok(truncate(FH, 200), "fh resize to 200");
300*0Sstevel@tonic-gate    }
301*0Sstevel@tonic-gate
302*0Sstevel@tonic-gate    if ($needs_fh_reopen) {
303*0Sstevel@tonic-gate	close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
304*0Sstevel@tonic-gate    }
305*0Sstevel@tonic-gate
306*0Sstevel@tonic-gate    SKIP: {
307*0Sstevel@tonic-gate        if ($^O eq 'vos') {
308*0Sstevel@tonic-gate	    skip ("# TODO - hit VOS bug posix-973 - cannot resize an open file below the current file pos.", 5);
309*0Sstevel@tonic-gate	}
310*0Sstevel@tonic-gate
311*0Sstevel@tonic-gate	is(-s "Iofs.tmp", 200, "fh resize to 200 working (filename check)");
312*0Sstevel@tonic-gate
313*0Sstevel@tonic-gate	ok(truncate(FH, 0), "fh resize to zero");
314*0Sstevel@tonic-gate
315*0Sstevel@tonic-gate	if ($needs_fh_reopen) {
316*0Sstevel@tonic-gate	    close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
317*0Sstevel@tonic-gate	}
318*0Sstevel@tonic-gate
319*0Sstevel@tonic-gate	ok(-z "Iofs.tmp", "fh resize to zero working (filename check)");
320*0Sstevel@tonic-gate
321*0Sstevel@tonic-gate	close FH;
322*0Sstevel@tonic-gate
323*0Sstevel@tonic-gate	open(FH, ">>Iofs.tmp") or die "Can't open Iofs.tmp for appending";
324*0Sstevel@tonic-gate
325*0Sstevel@tonic-gate	binmode FH;
326*0Sstevel@tonic-gate	select FH;
327*0Sstevel@tonic-gate	$| = 1;
328*0Sstevel@tonic-gate	select STDOUT;
329*0Sstevel@tonic-gate
330*0Sstevel@tonic-gate	{
331*0Sstevel@tonic-gate	    use strict;
332*0Sstevel@tonic-gate	    print FH "x\n" x 200;
333*0Sstevel@tonic-gate	    ok(truncate(*FH{IO}, 100), "fh resize by IO slot");
334*0Sstevel@tonic-gate	}
335*0Sstevel@tonic-gate
336*0Sstevel@tonic-gate	if ($needs_fh_reopen) {
337*0Sstevel@tonic-gate	    close (FH); open (FH, ">>Iofs.tmp") or die "Can't reopen Iofs.tmp";
338*0Sstevel@tonic-gate	}
339*0Sstevel@tonic-gate
340*0Sstevel@tonic-gate	is(-s "Iofs.tmp", 100, "fh resize by IO slot working");
341*0Sstevel@tonic-gate
342*0Sstevel@tonic-gate	close FH;
343*0Sstevel@tonic-gate    }
344*0Sstevel@tonic-gate}
345*0Sstevel@tonic-gate
346*0Sstevel@tonic-gate# check if rename() can be used to just change case of filename
347*0Sstevel@tonic-gateSKIP: {
348*0Sstevel@tonic-gate    skip "Works in Cygwin only if check_case is set to relaxed", 1
349*0Sstevel@tonic-gate      if $^O eq 'cygwin';
350*0Sstevel@tonic-gate
351*0Sstevel@tonic-gate    chdir './tmp';
352*0Sstevel@tonic-gate    open(fh,'>x') || die "Can't create x";
353*0Sstevel@tonic-gate    close(fh);
354*0Sstevel@tonic-gate    rename('x', 'X');
355*0Sstevel@tonic-gate
356*0Sstevel@tonic-gate    # this works on win32 only, because fs isn't casesensitive
357*0Sstevel@tonic-gate    ok(-e 'X', "rename working");
358*0Sstevel@tonic-gate
359*0Sstevel@tonic-gate    1 while unlink 'X';
360*0Sstevel@tonic-gate    chdir $wd || die "Can't cd back to $wd";
361*0Sstevel@tonic-gate}
362*0Sstevel@tonic-gate
363*0Sstevel@tonic-gate# check if rename() works on directories
364*0Sstevel@tonic-gateif ($^O eq 'VMS') {
365*0Sstevel@tonic-gate    # must have delete access to rename a directory
366*0Sstevel@tonic-gate    `set file tmp.dir/protection=o:d`;
367*0Sstevel@tonic-gate    ok(rename('tmp.dir', 'tmp1.dir'), "rename on directories") ||
368*0Sstevel@tonic-gate      print "# errno: $!\n";
369*0Sstevel@tonic-gate} else {
370*0Sstevel@tonic-gate    ok(rename('tmp', 'tmp1'), "rename on directories");
371*0Sstevel@tonic-gate}
372*0Sstevel@tonic-gate
373*0Sstevel@tonic-gateok(-d 'tmp1', "rename on directories working");
374*0Sstevel@tonic-gate
375*0Sstevel@tonic-gate# need to remove 'tmp' if rename() in test 28 failed!
376*0Sstevel@tonic-gateEND { rmdir 'tmp1'; rmdir 'tmp'; unlink "Iofs.tmp"; }
377