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