Mercurial > hg > octave-kai > gnulib-hg
annotate lib/filemode.c @ 12518:b5e42ef33b49
update nearly all FSF copyright year lists to include 2009
The files named by the following are exempted:
grep -v '^#' config/srclist.txt|grep -v '^$' \
| while read src dst; do
test -f "$dst" && { echo "$dst"; continue; }
test -d "$dst" || continue
echo "$dst"/$(basename "$src")
done > exempt
git ls-files tests/unictype >> exempt
In the remaining files, convert to all-interval notation if
- there is already at least one year interval like 2000-2003
- the file is maintained by me
- the file is in lib/uni*/, where that style already prevails
Otherwise, use update-copyright's default.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Mon, 28 Dec 2009 10:50:36 +0100 |
parents | e8d2c6fc33ad |
children | c2cbabec01dd |
rev | line source |
---|---|
5 | 1 /* filemode.c -- make a string describing file modes |
6912 | 2 |
12518
b5e42ef33b49
update nearly all FSF copyright year lists to include 2009
Jim Meyering <meyering@redhat.com>
parents:
12421
diff
changeset
|
3 Copyright (C) 1985, 1990, 1993, 1998-2000, 2004, 2006, 2009 Free Software |
6912 | 4 Foundation, Inc. |
5 | 5 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7581
diff
changeset
|
6 This program is free software: you can redistribute it and/or modify |
5 | 7 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7581
diff
changeset
|
8 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7581
diff
changeset
|
9 (at your option) any later version. |
5 | 10 |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7581
diff
changeset
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
2426
b22a7367bcf5
Use `C' to denote so-called `contiguous' files, the same way that tar does.
Jim Meyering <jim@meyering.net>
parents:
1814
diff
changeset
|
18 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6912
diff
changeset
|
19 #include <config.h> |
297 | 20 |
6912 | 21 #include "filemode.h" |
297 | 22 |
6912 | 23 /* The following is for Cray DMF (Data Migration Facility), which is a |
24 HSM file system. A migrated file has a `st_dm_mode' that is | |
25 different from the normal `st_mode', so any tests for migrated | |
26 files should use the former. */ | |
27 #if HAVE_ST_DM_MODE | |
28 # define IS_MIGRATED_FILE(statp) \ | |
29 (S_ISOFD (statp->st_dm_mode) || S_ISOFL (statp->st_dm_mode)) | |
30 #else | |
31 # define IS_MIGRATED_FILE(statp) 0 | |
32 #endif | |
5 | 33 |
6912 | 34 #if ! HAVE_DECL_STRMODE |
5 | 35 |
36 /* Return a character indicating the type of file described by | |
37 file mode BITS: | |
6912 | 38 '-' regular file |
39 'b' block special file | |
40 'c' character special file | |
41 'C' high performance ("contiguous data") file | |
42 'd' directory | |
43 'D' door | |
44 'l' symbolic link | |
45 'm' multiplexed file (7th edition Unix; obsolete) | |
46 'n' network special file (HP-UX) | |
47 'p' fifo (named pipe) | |
48 'P' port | |
49 's' socket | |
50 'w' whiteout (4.4BSD) | |
51 '?' some other file type */ | |
5 | 52 |
53 static char | |
1814
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
54 ftypelet (mode_t bits) |
5 | 55 { |
6912 | 56 /* These are the most common, so test for them first. */ |
57 if (S_ISREG (bits)) | |
58 return '-'; | |
59 if (S_ISDIR (bits)) | |
60 return 'd'; | |
61 | |
62 /* Other letters standardized by POSIX 1003.1-2004. */ | |
5 | 63 if (S_ISBLK (bits)) |
64 return 'b'; | |
65 if (S_ISCHR (bits)) | |
66 return 'c'; | |
6912 | 67 if (S_ISLNK (bits)) |
68 return 'l'; | |
5 | 69 if (S_ISFIFO (bits)) |
70 return 'p'; | |
6912 | 71 |
72 /* Other file types (though not letters) standardized by POSIX. */ | |
5 | 73 if (S_ISSOCK (bits)) |
74 return 's'; | |
6912 | 75 |
76 /* Nonstandard file types. */ | |
77 if (S_ISCTG (bits)) | |
78 return 'C'; | |
79 if (S_ISDOOR (bits)) | |
80 return 'D'; | |
81 if (S_ISMPB (bits) || S_ISMPC (bits)) | |
5 | 82 return 'm'; |
83 if (S_ISNWK (bits)) | |
84 return 'n'; | |
6912 | 85 if (S_ISPORT (bits)) |
86 return 'P'; | |
87 if (S_ISWHT (bits)) | |
88 return 'w'; | |
711
e80b482cadad
(ftypelet): Add support for Cray's migrated dmf files.
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
89 |
5 | 90 return '?'; |
91 } | |
92 | |
6912 | 93 /* Like filemodestring, but rely only on MODE. */ |
5 | 94 |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
95 void |
6912 | 96 strmode (mode_t mode, char *str) |
5 | 97 { |
1814
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
98 str[0] = ftypelet (mode); |
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
99 str[1] = mode & S_IRUSR ? 'r' : '-'; |
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
100 str[2] = mode & S_IWUSR ? 'w' : '-'; |
6912 | 101 str[3] = (mode & S_ISUID |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
102 ? (mode & S_IXUSR ? 's' : 'S') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
103 : (mode & S_IXUSR ? 'x' : '-')); |
1814
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
104 str[4] = mode & S_IRGRP ? 'r' : '-'; |
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
105 str[5] = mode & S_IWGRP ? 'w' : '-'; |
6912 | 106 str[6] = (mode & S_ISGID |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
107 ? (mode & S_IXGRP ? 's' : 'S') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
108 : (mode & S_IXGRP ? 'x' : '-')); |
1814
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
109 str[7] = mode & S_IROTH ? 'r' : '-'; |
e8f03a041d0e
(setst, ftypelet, mode_string): Use proper mode_t types and macros.
Jim Meyering <jim@meyering.net>
parents:
1697
diff
changeset
|
110 str[8] = mode & S_IWOTH ? 'w' : '-'; |
6912 | 111 str[9] = (mode & S_ISVTX |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
112 ? (mode & S_IXOTH ? 't' : 'T') |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
113 : (mode & S_IXOTH ? 'x' : '-')); |
6912 | 114 str[10] = ' '; |
115 str[11] = '\0'; | |
5 | 116 } |
117 | |
6912 | 118 #endif /* ! HAVE_DECL_STRMODE */ |
119 | |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
120 /* filemodestring - fill in string STR with an ls-style ASCII |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
121 representation of the st_mode field of file stats block STATP. |
6912 | 122 12 characters are stored in STR. |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
123 The characters stored in STR are: |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
124 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
125 0 File type, as in ftypelet above, except that other letters are used |
6912 | 126 for files whose type cannot be determined solely from st_mode: |
127 | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
128 'F' semaphore |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
129 'M' migrated file (Cray DMF) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
130 'Q' message queue |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
131 'S' shared memory object |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
132 'T' typed memory object |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
133 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
134 1 'r' if the owner may read, '-' otherwise. |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
135 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
136 2 'w' if the owner may write, '-' otherwise. |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
137 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
138 3 'x' if the owner may execute, 's' if the file is |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
139 set-user-id, '-' otherwise. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
140 'S' if the file is set-user-id, but the execute |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
141 bit isn't set. |
5 | 142 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
143 4 'r' if group members may read, '-' otherwise. |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
144 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
145 5 'w' if group members may write, '-' otherwise. |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
146 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
147 6 'x' if group members may execute, 's' if the file is |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
148 set-group-id, '-' otherwise. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
149 'S' if it is set-group-id but not executable. |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
150 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
151 7 'r' if any user may read, '-' otherwise. |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
152 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
153 8 'w' if any user may write, '-' otherwise. |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
154 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
155 9 'x' if any user may execute, 't' if the file is "sticky" |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
156 (will be retained in swap space after execution), '-' |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
157 otherwise. |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
158 'T' if the file is sticky but not executable. |
6912 | 159 |
160 10 ' ' for compatibility with 4.4BSD strmode, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
161 since this interface does not support ACLs. |
6912 | 162 |
163 11 '\0'. */ | |
1472
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
164 |
9bb334c7c86e
Protoize. Tsort function definitions and remove prototypes of
Jim Meyering <jim@meyering.net>
parents:
1470
diff
changeset
|
165 void |
6912 | 166 filemodestring (struct stat const *statp, char *str) |
5 | 167 { |
6912 | 168 strmode (statp->st_mode, str); |
169 | |
170 if (S_TYPEISSEM (statp)) | |
171 str[0] = 'F'; | |
172 else if (IS_MIGRATED_FILE (statp)) | |
173 str[0] = 'M'; | |
174 else if (S_TYPEISMQ (statp)) | |
175 str[0] = 'Q'; | |
176 else if (S_TYPEISSHM (statp)) | |
177 str[0] = 'S'; | |
178 else if (S_TYPEISTMO (statp)) | |
179 str[0] = 'T'; | |
5 | 180 } |