README
1NAME
2 File::Stat::Bits - stat(2) bit mask constants
3
4SYNOPSIS
5 use File::stat;
6 use File::Stat::Bits;
7
8 my $st = stat($file) or die "Can't stat $file: $!";
9
10 if ( S_ISCHR($st->mode) ) {
11 my ($major, $minor) = dev_split( $st->rdev );
12
13 print "$file is character device $major:$minor\n";
14 }
15
16 printf "Permissions are %04o\n", $st->mode & ALLPERMS;
17
18 (Too many S_IF* constants to example)
19
20DESCRIPTION
21 Lots of Perl modules use the Unix file permissions and type bits
22 directly in binary form with risk of non-portability for some exotic
23 bits. Note that the POSIX module does not provides all needed constants
24 and I can't wait when the POSIX module will be updated.
25
26 This separate module provides file type/mode bit and more constants from
27 sys/stat.ph and sys/sysmacros.ph without pollution caller's namespace by
28 other unneeded symbols from these headers. Most of these constants
29 exported by this module are Constant Functions (see perlsub).
30
31 Since some of Perl builds does not include these converted headers, the
32 build procedure will generate it for itself in the its own lib
33 directory.
34
35 This module also should concentrate all portability and compatibility
36 issues.
37
38CONSTANTS
39
40 File type bit masks (for the st_mode field):
41
42 S_IFMT bitmask for the file type bitfields
43 S_IFDIR directory
44 S_IFCHR character device
45 S_IFBLK block device
46 S_IFREG regular file
47 S_IFIFO fifo (named pipe)
48 S_IFLNK symbolic link
49 S_IFSOCK socket
50 =cut
51
52 sub S_IFMT () { File::Stat::Bits::dirty::S_IFMT () }
53 sub S_IFDIR () { File::Stat::Bits::dirty::S_IFDIR () }
54 sub S_IFCHR () { File::Stat::Bits::dirty::S_IFCHR () }
55 sub S_IFBLK () { File::Stat::Bits::dirty::S_IFBLK () }
56 sub S_IFREG () { File::Stat::Bits::dirty::S_IFREG () }
57 sub S_IFIFO () { File::Stat::Bits::dirty::S_IFIFO () }
58 sub S_IFLNK () { File::Stat::Bits::dirty::S_IFLNK () }
59 sub S_IFSOCK() { File::Stat::Bits::dirty::S_IFSOCK() }
60
61
62 File access permission bit masks (for the st_mode field):
63
64 S_IRWXU mask for file owner permissions
65 S_IRUSR owner has read permission
66 S_IWUSR owner has write permission
67 S_IXUSR owner has execute permission
68 S_ISUID set UID bit
69
70 S_IRWXG mask for group permissions
71 S_IRGRP group has read permission
72 S_IWGRP group has write permission
73 S_IXGRP group has execute permission
74 S_ISGID set GID bit
75
76 S_IRWXO mask for permissions for others
77 S_IROTH others have read permission
78 S_IWOTH others have write permisson
79 S_IXOTH others have execute permission
80 S_ISVTX sticky bit
81
82 Common mode bit masks:
83
84 ACCESSPERMS 0777
85 ALLPERMS 07777
86 DEFFILEMODE 0666
87 =cut
88
89 sub S_IRWXU() { File::Stat::Bits::dirty::S_IRWXU() }
90 sub S_IRUSR() { File::Stat::Bits::dirty::S_IRUSR() }
91 sub S_IWUSR() { File::Stat::Bits::dirty::S_IWUSR() }
92 sub S_IXUSR() { File::Stat::Bits::dirty::S_IXUSR() }
93 sub S_ISUID() { File::Stat::Bits::dirty::S_ISUID() }
94
95 sub S_IRWXG() { File::Stat::Bits::dirty::S_IRWXG() }
96 sub S_IRGRP() { File::Stat::Bits::dirty::S_IRGRP() }
97 sub S_IWGRP() { File::Stat::Bits::dirty::S_IWGRP() }
98 sub S_IXGRP() { File::Stat::Bits::dirty::S_IXGRP() }
99 sub S_ISGID() { File::Stat::Bits::dirty::S_ISGID() }
100
101 sub S_IRWXO() { File::Stat::Bits::dirty::S_IRWXO() }
102 sub S_IROTH() { File::Stat::Bits::dirty::S_IROTH() }
103 sub S_IWOTH() { File::Stat::Bits::dirty::S_IWOTH() }
104 sub S_IXOTH() { File::Stat::Bits::dirty::S_IXOTH() }
105 sub S_ISVTX() { File::Stat::Bits::dirty::S_ISVTX() }
106
107 sub ACCESSPERMS() { S_IRWXU|S_IRWXG|S_IRWXO }
108 sub ALLPERMS() { S_ISUID|S_ISGID|S_ISVTX|ACCESSPERMS }
109 sub DEFFILEMODE() { S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH }
110
111FUNCTIONS
112
113 File type test macros (for the st_mode field):
114
115 S_ISDIR ( mode ) directory?
116 S_ISCHR ( mode ) character device?
117 S_ISBLK ( mode ) block device?
118 S_ISREG ( mode ) regular file?
119 S_ISFIFO( mode ) fifo (named pipe)?
120 S_ISLNK ( mode ) is it a symbolic link?
121 S_ISSOCK( mode ) socket?
122
123 All returns boolean value.
124
125
126 $major = major( $st_rdev )
127
128 Returns major device number of st_rdev
129
130
131 $minor = minor( $st_rdev )
132
133 Returns minor device number of st_rdev
134
135
136 ($major, $minor) = dev_split( $st_rdev )
137
138 Splits st_rdev to major and minor device numbers
139
140
141 $st_rdev = dev_join( $major, $minor )
142
143 Makes st_rdev from major and minor device numbers (makedev())
144
145NOTE
146 If major/minor definitions absent in reasonable set of system C headers
147 all major/minor related functions returns undef.
148
149SEE ALSO
150 stat(2)
151
152 File::stat(3)
153
154AUTHOR
155 Dmitry Fedorov <dm.fedorov@gmail.com>
156
157COPYRIGHT
158 Copyright (C) 2003 Dmitry Fedorov <dm.fedorov@gmail.com>
159
160LICENSE
161 This program is free software; you can redistribute it and/or modify it
162 under the terms of the GNU General Public License as published by the
163 Free Software Foundation; either version 2 of the License, or (at your
164 option) any later version.
165
166DISCLAIMER
167 The author disclaims any responsibility for any mangling of your system
168 etc, that this script may cause.
169
170