Merge branch 'master' of http://repo.or.cz/r/msysgit into devel
[msysgit/historical-msysgit.git] / lib / perl5 / 5.6.1 / filetest.pm
blobb52a9b484d58b93c250f9397e0d5a0aca6acf51e
1 package filetest;
3 =head1 NAME
5 filetest - Perl pragma to control the filetest permission operators
7 =head1 SYNOPSIS
9 $can_perhaps_read = -r "file"; # use the mode bits
11 use filetest 'access'; # intuit harder
12 $can_really_read = -r "file";
14 $can_perhaps_read = -r "file"; # use the mode bits again
16 =head1 DESCRIPTION
18 This pragma tells the compiler to change the behaviour of the filetest
19 permissions operators, the C<-r> C<-w> C<-x> C<-R> C<-W> C<-X>
20 (see L<perlfunc>).
22 The default behaviour to use the mode bits as returned by the stat()
23 family of calls. This, however, may not be the right thing to do if
24 for example various ACL (access control lists) schemes are in use.
25 For such environments, C<use filetest> may help the permission
26 operators to return results more consistent with other tools.
28 Each "use filetest" or "no filetest" affects statements to the end of
29 the enclosing block.
31 There may be a slight performance decrease in the filetests
32 when C<use filetest> is in effect, because in some systems
33 the extended functionality needs to be emulated.
35 B<NOTE>: using the file tests for security purposes is a lost cause
36 from the start: there is a window open for race conditions (who is to
37 say that the permissions will not change between the test and the real
38 operation?). Therefore if you are serious about security, just try
39 the real operation and test for its success. Think atomicity.
41 =head2 subpragma access
43 Currently only one subpragma, C<access> is implemented. It enables
44 (or disables) the use of access() or similar system calls. This
45 extended filetest functionality is used only when the argument of the
46 operators is a filename, not when it is a filehandle.
48 =cut
50 $filetest::hint_bits = 0x00400000;
52 sub import {
53 if ( $_[1] eq 'access' ) {
54 $^H |= $filetest::hint_bits;
55 } else {
56 die "filetest: the only implemented subpragma is 'access'.\n";
60 sub unimport {
61 if ( $_[1] eq 'access' ) {
62 $^H &= ~$filetest::hint_bits;
63 } else {
64 die "filetest: the only implemented subpragma is 'access'.\n";