Debian Codegraph @

t/op/stat.t

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 #!./perl
2
3 BEGIN {
4 chdir 't' if -d 't';
5 require './test.pl'; # for which_perl() etc
6 set_up_inc('../lib');
7 }
8
9 use strict;
10 use warnings;
11 use Config;
12
13 my ($Null, $Curdir);
14 if(eval {require File::Spec; 1}) {
15 $Null = File::Spec->devnull;
16 $Curdir = File::Spec->curdir;
17 } else {
18 die $@ unless is_miniperl();
19 $Curdir = '.';
20 diag("miniperl failed to load File::Spec, error is:\n$@");
21 diag("\ncontinuing, assuming '.' for current directory. Some tests will be skipped.");
22 }
23
24 if ($^O eq 'MSWin32') {
25 # under minitest, buildcustomize sets this to 1, which means
26 # nlinks isn't populated properly, allow nlinks tests to pass
27 ${^WIN32_SLOPPY_STAT} = 0;
28 }
29
30 my $Errno_loaded = eval { require Errno };
31
32 plan tests => 111;
33
34 my $Perl = which_perl();
35
36 $ENV{LC_ALL} = 'C'; # Forge English error messages.
37 $ENV{LANGUAGE} = 'C'; # Ditto in GNU.
38
39 my $Is_Amiga = $^O eq 'amigaos';
40 my $Is_Cygwin = $^O eq 'cygwin';
41 my $Is_Darwin = $^O eq 'darwin';
42 my $Is_MSWin32 = $^O eq 'MSWin32';
43 my $Is_OS2 = $^O eq 'os2';
44 my $Is_Solaris = $^O eq 'solaris';
45 my $Is_VMS = $^O eq 'VMS';
46 my $Is_MPRAS = $^O =~ /svr4/ && -f '/etc/.relid';
47 my $Is_Android = $^O =~ /android/;
48 my $Is_Dfly = $^O eq 'dragonfly';
49
50 my $Is_Dosish = $Is_OS2 || $Is_MSWin32;
51
52 my $ufs_no_ctime = ($Is_Dfly || $Is_Darwin) && (() = `df -t ufs . 2>/dev/null`) == 2;
53
54 my $Is_linux_container = is_linux_container();
55
56 if ($Is_Cygwin && !is_miniperl) {
57 require Win32;
58 Win32->import;
59 }
60
61 my($DEV, $INO, $MODE, $NLINK, $UID, $GID, $RDEV, $SIZE,
62 $ATIME, $MTIME, $CTIME, $BLKSIZE, $BLOCKS) = (0..12);
63
64 my $tmpfile = tempfile();
65 my $tmpfile_link = tempfile();
66
67 chmod 0666, $tmpfile;
68 unlink_all $tmpfile;
69 open(FOO, ">$tmpfile") || DIE("Can't open temp test file: $!");
70 close FOO;
71
72 open(FOO, ">$tmpfile") || DIE("Can't open temp test file: $!");
73
74 my($nlink, $mtime, $ctime) = (stat(FOO))[$NLINK, $MTIME, $CTIME];
75
76 # The clock on a network filesystem might be different from the
77 # system clock.
78 my $Filesystem_Time_Offset = abs($mtime - time);
79
80 #nlink should if link support configured in Perl.
81 SKIP: {
82 skip "No link count - Hard link support not built in.", 1
83 unless $Config{d_link};
84
85 is($nlink, 1, 'nlink on regular file');
86 }
87
88 SKIP: {
89 skip "mtime and ctime not reliable", 2
90 if $Is_MSWin32 or $Is_Cygwin or $Is_Darwin;
91
92 ok( $mtime, 'mtime' );
93 is( $mtime, $ctime, 'mtime == ctime' );
94 }
95
96
97 # Cygwin seems to have a 3 second granularity on its timestamps.
98 my $funky_FAT_timestamps = $Is_Cygwin;
99 sleep 3 if $funky_FAT_timestamps;
100
101 print FOO "Now is the time for all good men to come to.\n";
102 close(FOO);
103
104 sleep 2;
105
106 my $has_link = 1;
107 my $inaccurate_atime = 0;
108 if (defined &Win32::IsWinNT && Win32::IsWinNT()) {
109 if (Win32::FsType() ne 'NTFS') {
110 $has_link = 0;
111 $inaccurate_atime = 1;
112 }
113 }
114
115 SKIP: {
116 skip "No link on this filesystem", 6 unless $has_link;
117 unlink $tmpfile_link;
118 my $lnk_result = eval { link $tmpfile, $tmpfile_link };
119 skip "link() unimplemented", 6 if $@ =~ /unimplemented/;
120
121 is( $@, '', 'link() implemented' );
122 ok( $lnk_result, 'linked tmp testfile' );
123 ok( chmod(0644, $tmpfile), 'chmoded tmp testfile' );
124
125 my($nlink, $mtime, $ctime) = (stat($tmpfile))[$NLINK, $MTIME, $CTIME];
126
127 SKIP: {
128 skip "No link count", 1 if $Config{dont_use_nlink};
129 skip "Cygwin9X fakes hard links by copying", 1
130 if $Config{myuname} =~ /^cygwin_(?:9\d|me)\b/i;
131
132 is($nlink, 2, 'Link count on hard linked file' );
133 }
134
135 SKIP: {
136 skip_if_miniperl("File::Spec not built for minitest", 2);
137 my $cwd = File::Spec->rel2abs($Curdir);
138 skip "Solaris tmpfs has different mtime/ctime link semantics", 2
139 if $Is_Solaris and $cwd =~ m#^/tmp# and
140 $mtime && $mtime == $ctime;
141 skip "AFS has different mtime/ctime link semantics", 2
142 if $cwd =~ m#$Config{'afsroot'}/#;
143 skip "AmigaOS has different mtime/ctime link semantics", 2
144 if $Is_Amiga;
145 # Win32 could pass $mtime test but as FAT and NTFS have
146 # no ctime concept $ctime is ALWAYS == $mtime
147 skip "No ctime concept on this OS", 2
148 if $Is_MSWin32 || $ufs_no_ctime;
149 my $ok_mtime = ok($mtime, 'hard link mtime');
150 local our $TODO;
151 # https://bugs.dragonflybsd.org/issues/3251
152 # this might be hammer/hammer2 specific
153 $TODO = "DragonFly BSD doesn't touch ctime on link()/chmod"
154 if $^O eq "dragonfly" && $Config{myuname} =~ /5\.8/;
155 if(!$ok_mtime ||
156 !isnt($mtime, $ctime, 'hard link ctime != mtime') ) {
157 print STDERR <<DIAG;
158 # Check if you are on a tmpfs of some sort. Building in /tmp sometimes
159 # has this problem. Building on the ClearCase VOBS filesystem may also
160 # cause this failure.
161 #
162 # Some UFS implementations don't have a ctime concept, and thus are
163 # expected to fail this test.
164 DIAG
165 }
166 }
167
168 }
169
170 # truncate and touch $tmpfile.
171 open(F, ">$tmpfile") || DIE("Can't open temp test file: $!");
172 ok(-z \*F, '-z on empty filehandle');
173 ok(! -s \*F, ' and -s');
174 close F;
175
176 ok(-z $tmpfile, '-z on empty file');
177 ok(! -s $tmpfile, ' and -s');
178
179 open(F, ">$tmpfile") || DIE("Can't open temp test file: $!");
180 print F "hi\n";
181 close F;
182
183 open(F, "<$tmpfile") || DIE("Can't open temp test file: $!");
184 ok(!-z *F, '-z on empty filehandle');
185 ok( -s *F, ' and -s');
186 close F;
187
188 ok(! -z $tmpfile, '-z on non-empty file');
189 ok(-s $tmpfile, ' and -s');
190
191
192 # Strip all access rights from the file.
193 ok( chmod(0000, $tmpfile), 'chmod 0000' );
194
195 SKIP: {
196 skip "-r, -w and -x have different meanings on VMS", 3 if $Is_VMS;
197
198 SKIP: {
199 # Going to try to switch away from root. Might not work.
200 my $olduid = $>;
201 eval { $> = 1; };
202 skip "Can't test -r or -w meaningfully if you're superuser", 2
203 if ($Is_Cygwin ? _ingroup(544, 1) : $> == 0);
204
205 ok(!-r $tmpfile, " -r");
206 ok(!-w $tmpfile, " -w");
207
208 # switch uid back (may not be implemented)
209 eval { $> = $olduid; };
210 }
211
212 ok(! -x $tmpfile, ' -x');
213 }
214
215
216
217 ok(chmod(0700,$tmpfile), 'chmod 0700');
218 ok(-r $tmpfile, ' -r');
219 ok(-w $tmpfile, ' -w');
220
221 SKIP: {
222 skip "-x simply determines if a file ends in an executable suffix", 1
223 if $Is_Dosish;
224
225 ok(-x $tmpfile, ' -x');
226 }
227
228 ok( -f $tmpfile, ' -f');
229 ok(! -d $tmpfile, ' !-d');
230
231 # Is this portable?
232 ok( -d '.', '-d cwd' );
233 ok(! -f '.', '!-f cwd' );
234
235
236 SKIP: {
237 unlink($tmpfile_link);
238 my $symlink_rslt = eval { symlink $tmpfile, $tmpfile_link };
239 my $error = 0 + $!;
240 skip "symlink not implemented", 3 if $@ =~ /unimplemented/;
241 skip "symlink not available or we can't check", 3
242 if $^O eq "MSWin32" && (!$Errno_loaded || $error == &Errno::ENOSYS || $error == &Errno::EPERM);
243
244 is( $@, '', 'symlink() implemented' );
245 ok( $symlink_rslt, 'symlink() ok' );
246 ok(-l $tmpfile_link, '-l');
247 }
248
249 ok(-o $tmpfile, '-o');
250
251 ok(-e $tmpfile, '-e');
252
253 unlink($tmpfile_link);
254 ok(! -e $tmpfile_link, ' -e on unlinked file');
255
256 SKIP: {
257 skip "No character, socket or block special files", 6
258 if $Is_MSWin32;
259 skip "/dev isn't available to test against", 6
260 unless -d '/dev' && -r '/dev' && -x '/dev';
261 skip "Skipping: unexpected ls output in MP-RAS", 6
262 if $Is_MPRAS;
263
264 # VMS problem: If GNV or other UNIX like tool is installed, then
265 # sometimes Perl will find /bin/ls, and will try to run it.
266 # But since Perl on VMS does not know to run it under Bash, it will
267 # try to run the DCL verb LS. And if the VMS product Language
268 # Sensitive Editor is installed, or some other LS verb, that will
269 # be run instead. So do not do this until we can teach Perl
270 # when to use BASH on VMS.
271 skip "ls command not available to Perl in OpenVMS right now.", 6
272 if $Is_VMS;
273
274 delete $ENV{CLICOLOR_FORCE};
275 my $LS = $Config{d_readlink} && !$Is_Android ? "ls -lL" : "ls -l";
276 my $CMD = "$LS /dev 2>/dev/null";
277 my $DEV = qx($CMD);
278
279 skip "$CMD failed", 6 if $DEV eq '';
280
281 my @DEV = do { my $dev; opendir($dev, "/dev") ? readdir($dev) : () };
282
283 skip "opendir failed: $!", 6 if @DEV == 0;
284
285 # /dev/stdout might be either character special or a named pipe,
286 # or a symlink, or a socket, depending on which OS and how are
287 # you running the test, so let's censor that one away.
288 # Similar remarks hold for stderr.
289 $DEV =~ s{^[cpls].+?\sstdout$}{}m;
290 @DEV = grep { $_ ne 'stdout' } @DEV;
291 $DEV =~ s{^[cpls].+?\sstderr$}{}m;
292 @DEV = grep { $_ ne 'stderr' } @DEV;
293
294 # /dev/printer is also naughty: in IRIX it shows up as
295 # Srwx-----, not srwx------.
296 $DEV =~ s{^.+?\sprinter$}{}m;
297 @DEV = grep { $_ ne 'printer' } @DEV;
298
299 # If running as root, we will see .files in the ls result,
300 # and readdir() will see them always. Potential for conflict,
301 # so let's weed them out.
302 $DEV =~ s{^.+?\s\..+?$}{}m;
303 @DEV = grep { ! m{^\..+$} } @DEV;
304
305 # sometimes files cannot be stat'd on cygwin, making inspecting pointless
306 # remove them from both @DEV and $DEV
307 @DEV = grep $DEV =~ s/^.\?{9}.*\s$_(?: -> .*)?$//m ? () : $_, @DEV
308 if $Is_Cygwin;
309
310 # Irix ls -l marks sockets with 'S' while 's' is a 'XENIX semaphore'.
311 if ($^O eq 'irix') {
312 $DEV =~ s{^S(.+?)}{s$1}mg;
313 }
314
315 my $try = sub {
316 my @c1 = eval qq[\$DEV =~ /^$_[0].*/mg];
317 my @c2 = eval qq[grep { $_[1] "/dev/\$_" } \@DEV];
318 my $c1 = scalar @c1;
319 my $c2 = scalar @c2;
320 diag "= before", $DEV, "-", @DEV, "= after", @c1, "-", @c2, "="
321 unless is($c1, $c2, "ls and $_[1] agreeing on /dev ($c1 $c2)");
322 };
323
324 {
325 $try->('b', '-b');
326 $try->('c', '-c');
327 $try->('s', '-S');
328 }
329
330 ok(! -b $Curdir, '!-b cwd');
331 ok(! -c $Curdir, '!-c cwd');
332 ok(! -S $Curdir, '!-S cwd');
333
334 }
335
336 SKIP: {
337 my($cnt, $uid);
338 $cnt = $uid = 0;
339
340 # Find a set of directories that's very likely to have setuid files
341 # but not likely to be *all* setuid files.
342 my @bin = grep {-d && -r && -x} qw(/sbin /usr/sbin /bin /usr/bin);
343 skip "Can't find a setuid file to test with", 3 unless @bin;
344
345 for my $bin (@bin) {
346 opendir BIN, $bin or die "Can't opendir $bin: $!";
347 while (defined($_ = readdir BIN)) {
348 $_ = "$bin/$_";
349 $cnt++;
350 $uid++ if -u;
351 last if $uid && $uid < $cnt;
352 }
353 }
354 closedir BIN;
355
356 skip "No setuid programs", 3 if $uid == 0;
357
358 isnt($cnt, 0, 'found some programs');
359 isnt($uid, 0, ' found some setuid programs');
360 ok($uid < $cnt, " they're not all setuid");
361 }
362
363
364 # To assist in automated testing when a controlling terminal (/dev/tty)
365 # may not be available (at, cron rsh etc), the PERL_SKIP_TTY_TEST env var
366 # can be set to skip the tests that need a tty.
367 SKIP: {
368 skip "These tests require a TTY", 4 if $ENV{PERL_SKIP_TTY_TEST};
369 skip "Skipping TTY tests on linux containers", 4 if $Is_linux_container;
370
371 my $TTY = "/dev/tty";
372
373 SKIP: {
374 skip "Test uses unixisms", 2 if $Is_MSWin32;
375 skip "No TTY to test -t with", 2 unless -e $TTY;
376
377 open(TTY, $TTY) ||
378 warn "Can't open $TTY--run t/TEST outside of make.\n";
379 ok(-t TTY, '-t');
380 ok(-c TTY, 'tty is -c');
381 close(TTY);
382 }
383 ok(! -t TTY, '!-t on closed TTY filehandle');
384
385 {
386 local our $TODO = 'STDIN not a tty when output is to pipe' if $Is_VMS;
387 ok(-t, '-t on STDIN');
388 }
389 }
390
391 SKIP: {
392 skip "No null device to test with", 1 unless -e $Null;
393 skip "We know Win32 thinks '$Null' is a TTY", 1 if $Is_MSWin32;
394
395 open(NULL, $Null) or DIE("Can't open $Null: $!");
396 ok(! -t NULL, 'null device is not a TTY');
397 close(NULL);
398 }
399
400
401 # These aren't strictly "stat" calls, but so what?
402 my $statfile = './op/stat.t';
403 ok( -T $statfile, '-T');
404 ok(! -B $statfile, '!-B');
405 ok(-B $Perl, '-B');
406 ok(! -T $Perl, '!-T');
407
408 open(FOO,$statfile);
409 SKIP: {
410 eval { -T FOO; };
411 skip "-T/B on filehandle not implemented", 15 if $@ =~ /not implemented/;
412
413 is( $@, '', '-T on filehandle causes no errors' );
414
415 ok(-T FOO, ' -T');
416 ok(! -B FOO, ' !-B');
417
418 $_ = <FOO>;
419 like($_, qr/perl/, 'after readline');
420 ok(-T FOO, ' still -T');
421 ok(! -B FOO, ' still -B');
422 close(FOO);
423
424 open(FOO,$statfile);
425 $_ = <FOO>;
426 like($_, qr/perl/, 'reopened and after readline');
427 ok(-T FOO, ' still -T');
428 ok(! -B FOO, ' still !-B');
429
430 ok(seek(FOO,0,0), 'after seek');
431 ok(-T FOO, ' still -T');
432 ok(! -B FOO, ' still !-B');
433
434 # It's documented this way in perlfunc *shrug*
435 () = <FOO>;
436 ok(eof FOO, 'at EOF');
437 ok(-T FOO, ' still -T');
438 ok(-B FOO, ' now -B');
439 }
440 close(FOO);
441
442
443 SKIP: {
444 skip "No null device to test with", 2 unless -e $Null;
445
446 ok(-T $Null, 'null device is -T');
447 ok(-B $Null, ' and -B');
448 }
449
450
451 # and now, a few parsing tests:
452 $_ = $tmpfile;
453 ok(-f, 'bare -f uses $_');
454 ok(-f(), ' -f() "');
455
456 unlink $tmpfile or print "# unlink failed: $!\n";
457
458 # bug id 20011101.069 (#7861)
459 my @r = \stat($Curdir);
460 is(scalar @r, 13, 'stat returns full 13 elements');
461
462 stat $0;
463 eval { lstat _ };
464 like( $@, qr/^The stat preceding lstat\(\) wasn't an lstat/,
465 'lstat _ croaks after stat' );
466 eval { lstat *_ };
467 like( $@, qr/^The stat preceding lstat\(\) wasn't an lstat/,
468 'lstat *_ croaks after stat' );
469 eval { lstat \*_ };
470 like( $@, qr/^The stat preceding lstat\(\) wasn't an lstat/,
471 'lstat \*_ croaks after stat' );
472 eval { -l _ };
473 like( $@, qr/^The stat preceding -l _ wasn't an lstat/,
474 '-l _ croaks after stat' );
475
476 lstat $0;
477 eval { lstat _ };
478 is( "$@", "", "lstat _ ok after lstat" );
479 eval { -l _ };
480 is( "$@", "", "-l _ ok after lstat" );
481
482 eval { lstat "test.pl" };
483 {
484 open my $fh, "test.pl";
485 stat *$fh{IO};
486 eval { lstat _ }
487 }
488 like $@, qr/^The stat preceding lstat\(\) wasn't an lstat at /,
489 'stat $ioref resets stat type';
490
491 {
492 open(FOO, ">$tmpfile") || DIE("Can't open temp test file: $!");
493 my @statbuf = stat FOO;
494 stat "test.pl";
495 no warnings 'io';
496 my @lstatbuf = lstat *FOO{IO};
497 is "@lstatbuf", "@statbuf", 'lstat $ioref reverts to regular fstat';
498 close(FOO);
499 unlink $tmpfile or print "# unlink failed: $!\n";
500 }
501
502 SKIP: {
503 skip "No lstat", 2 unless $Config{d_lstat} && $Config{d_symlink};
504
505 # bug id 20020124.004 (#8334)
506 my $linkname = 'stat-' . rand =~ y/.//dr;
507 my $target = $Perl;
508 $target =~ s/;\d+\z// if $Is_VMS; # symlinks don't like version numbers
509 unless (symlink $target, $linkname) {
510 if ($^O eq "MSWin32") {
511 # likely we don't have permission
512 skip "symlink failed: $!", 2;
513 }
514 die "# Can't symlink $0: $!";
515 }
516 lstat $linkname;
517 -T _;
518 eval { lstat _ };
519 like( $@, qr/^The stat preceding lstat\(\) wasn't an lstat/,
520 'lstat croaks after -T _' );
521 eval { -l _ };
522 like( $@, qr/^The stat preceding -l _ wasn't an lstat/,
523 '-l _ croaks after -T _' );
524 unlink $linkname or print "# unlink $linkname failed: $!\n";
525 }
526
527 SKIP: {
528 skip "Too much clock skew between system and filesystem", 5
529 if ($Filesystem_Time_Offset > 5);
530 print "# Zzz...\n";
531 sleep($Filesystem_Time_Offset+1);
532 my $f = 'tstamp.tmp';
533 unlink $f;
534 ok (open(S, "> $f"), 'can create tmp file');
535 close S or die;
536 my @a = stat $f;
537 print "# time=$^T, stat=(@a)\n";
538 my @b = (-M _, -A _, -C _);
539 print "# -MAC=(@b)\n";
540 ok( (-M _) < 0, 'negative -M works');
541 SKIP:
542 {
543 skip "Access timestamps inaccurate", 1 if $inaccurate_atime;
544 ok( (-A _) < 0, 'negative -A works');
545 }
546 ok( (-C _) < 0, 'negative -C works');
547 ok(unlink($f), 'unlink tmp file');
548 }
549
550 # [perl #4253]
551 {
552 ok(open(F, ">", $tmpfile), 'can create temp file');
553 close F;
554 chmod 0077, $tmpfile;
555 my @a = stat($tmpfile);
556 my $s1 = -s _;
557 -T _;
558 my $s2 = -s _;
559 is($s1, $s2, q(-T _ doesn't break the statbuffer));
560 SKIP: {
561 my $root_uid = $Is_Cygwin ? 18 : 0;
562 skip "No lstat", 1 unless $Config{d_lstat};
563 skip "uid=0", 1 if $< == $root_uid or $> == $root_uid;
564 skip "Can't check if admin user in miniperl", 1
565 if $^O =~ /^(cygwin|MSWin32|msys)$/ && is_miniperl();
566 skip "Readable by group/other means readable by me on $^O", 1 if $^O eq 'VMS'
567 or ($^O =~ /^(cygwin|MSWin32|msys)$/ and Win32::IsAdminUser());
568 lstat($tmpfile);
569 -T _;
570 ok(eval { lstat _ },
571 q(-T _ doesn't break lstat for unreadable file));
572 }
573 unlink $tmpfile;
574 }
575
576 SKIP: {
577 skip "No dirfd()", 4 unless $Config{d_dirfd} || $Config{d_dir_dd_fd};
578 ok(opendir(DIR, "."), 'Can open "." dir') || diag "Can't open '.': $!";
579 ok(stat(DIR), "stat() on dirhandle works");
580 ok(-d -r _ , "chained -x's on dirhandle");
581 ok(-d DIR, "-d on a dirhandle works");
582 closedir DIR or die $!;
583 }
584
585 {
586 # RT #8244: *FILE{IO} does not behave like *FILE for stat() and -X() operators
587 ok(open(F, ">", $tmpfile), 'can create temp file');
588 my @thwap = stat *F{IO};
589 ok(@thwap, "stat(*F{IO}) works");
590 ok( -f *F{IO} , "single file tests work with *F{IO}");
591 close F;
592 unlink $tmpfile;
593
594 #PVIO's hold dirhandle information, so let's test them too.
595
596 SKIP: {
597 skip "No dirfd()", 4 unless $Config{d_dirfd} || $Config{d_dir_dd_fd};
598 ok(opendir(DIR, "."), 'Can open "." dir') || diag "Can't open '.': $!";
599 ok(stat(*DIR{IO}), "stat() on *DIR{IO} works");
600 ok(-d _ , "The special file handle _ is set correctly");
601 ok(-d -r *DIR{IO} , "chained -x's on *DIR{IO}");
602 closedir DIR or die $!;
603 }
604 }
605
606 # [perl #71002]
607 {
608 my $w;
609 local $SIG{__WARN__} = sub { warn shift; ++$w };
610 stat 'prepeinamehyparcheiarcheiometoonomaavto';
611 stat _;
612 is $w, undef, 'no unopened warning from stat _';
613 }
614
615 {
616 # [perl #123816]
617 # Inappropriate stacking of l?stat with filetests should either work or
618 # give a syntax error, they shouldn't crash.
619 eval { stat -t };
620 ok(1, 'can "stat -t" without crashing');
621 eval { lstat -t };
622 ok(1, 'can "lstat -t" without crashing');
623 }
624
625 # [perl #126064] stat stat stack busting
626 is join("-", 1,2,3,(stat stat stat),4,5,6), "1-2-3-4-5-6",
627 'stat inside stat gets scalar context';
628
629 # [perl #126162] stat an array should not work
630 # skip if -e '2'.
631 SKIP:
632 {
633 skip "There is a file named '2', which invalidates this test", 2 if -e '2';
634
635 my @statarg = ($statfile, $statfile);
636 no warnings 'syntax';
637 ok !stat(@statarg),
638 'stat on an array of valid paths should warn and should not return any data';
639 my $error = 0+$!;
640 skip "Errno not available", 1
641 unless $Errno_loaded;
642 is $error, &Errno::ENOENT,
643 'stat on an array of valid paths should return ENOENT';
644 }
645
646 # [perl #131895] stat() doesn't fail on filenames containing \0 / NUL
647 {
648 no warnings 'syscalls';
649 ok !stat("TEST\0-"), 'stat on filename with \0';
650 }
651 SKIP: {
652 my $link = "stat_t_$$\_TEST.symlink";
653 my $can_symlink = eval { symlink "TEST", $link };
654 skip "cannot symlink", 1 unless $can_symlink;
655 no warnings 'syscalls';
656 ok !lstat("$link\0-"), 'lstat on filename with \0';
657 unlink $link;
658 }
659
660 SKIP:
661 {
662 # test needs a FreeBSD /usr/bin/stat
663 # /tmp is typically tmpfs on a new FreeBSD
664 $^O eq "freebsd"
665 or skip "only checking freebsd for now", 1;
666 -x "/usr/bin/stat"
667 or skip "no /usr/bin/stat", 1;
668 my @s = stat "/tmp";
669 @s or skip "No /tmp found", 1;
670 my $test = `/usr/bin/stat -f '%d %i' /tmp`;
671 $test && $test =~ /^-?\d+ -?\d+/
672 or skip "stat didn't return an expected result";
673 chomp $test;
674 is("$s[0] $s[1]", $test,
675 "perl stat didn't match system stat utility");
676 }
677
678 END {
679 chmod 0666, $tmpfile;
680 unlink_all $tmpfile;
681 }
682
683 sub _ingroup {
684 my ($gid, $eff) = @_;
685
686 $^O eq "VMS" and return $_[0] == $);
687
688 my ($egid, @supp) = split " ", $);
689 my ($rgid) = split " ", $(;
690
691 $gid == ($eff ? $egid : $rgid) and return 1;
692 grep $gid == $_, @supp and return 1;
693
694 return "";
695 }