Mercurial > emacs
annotate src/filemode.c @ 83376:de684325b343
Merged in changes from CVS trunk.
Patches applied:
* lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-6
Update from CVS
* lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-7
Sync with miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-539.
* lorentey@elte.hu--2004/emacs--cvs-trunk--0--version-0
Branch closed. Use miles@gnu.org--gnu-2005/emacs--cvs-trunk--0 instead.
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-475
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-476
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-477
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-478
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-479
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-480
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-481
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-482
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-483
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-484
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-485
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-486
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-487
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-488
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-489
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-490
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-491
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-492
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-493
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-494
Update from CVS: lisp/startup.el (command-line): Fix typo.
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-495
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-496
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-497
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-498
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-499
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-500
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-501
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-502
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-503
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-504
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-505
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-506
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-507
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-508
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-509
Update from CVS: .cvsignore: Add `lock'.
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-510
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-511
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-512
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-513
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-514
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-515
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-516
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-517
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-518
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-519
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-520
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-521
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-522
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-523
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-524
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-525
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-526
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-527
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-528
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-529
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-530
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-531
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-532
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-533
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-534
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-535
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-536
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-537
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-538
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-539
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-88
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-89
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-90
Update FSF's address in GPL notices
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-91
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-92
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-93
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-94
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-95
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-96
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-97
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-98
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-99
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-100
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-101
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-102
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-103
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-104
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-105
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-106
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-107
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-108
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-109
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-110
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-111
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-112
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-113
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-114
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-416
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Sun, 11 Sep 2005 08:23:50 +0000 |
parents | a0d1312ede66 |
children | 3bd95f4f2941 2d92f5c9d6ae |
rev | line source |
---|---|
25843 | 1 /* filemode.c -- make a string describing file modes |
64770
a0d1312ede66
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64084
diff
changeset
|
2 Copyright (C) 1985, 1990, 1993, 2002, 2003, 2004, |
a0d1312ede66
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64084
diff
changeset
|
3 2005 Free Software Foundation, Inc. |
25843 | 4 |
5 This program is free software; you can redistribute it and/or modify | |
6 it under the terms of the GNU General Public License as published by | |
7 the Free Software Foundation; either version 2, or (at your option) | |
8 any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program; if not, write to the Free Software | |
64084 | 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
25843 | 18 USA. */ |
19 | |
20 #ifdef HAVE_CONFIG_H | |
21 #include <config.h> | |
22 #endif | |
23 | |
24 #include <sys/types.h> | |
25 #include <sys/stat.h> | |
26 | |
27 #if !S_IRUSR | |
28 # if S_IREAD | |
29 # define S_IRUSR S_IREAD | |
30 # else | |
31 # define S_IRUSR 00400 | |
32 # endif | |
33 #endif | |
34 | |
35 #if !S_IWUSR | |
36 # if S_IWRITE | |
37 # define S_IWUSR S_IWRITE | |
38 # else | |
39 # define S_IWUSR 00200 | |
40 # endif | |
41 #endif | |
42 | |
43 #if !S_IXUSR | |
44 # if S_IEXEC | |
45 # define S_IXUSR S_IEXEC | |
46 # else | |
47 # define S_IXUSR 00100 | |
48 # endif | |
49 #endif | |
50 | |
51 #ifdef STAT_MACROS_BROKEN | |
52 #undef S_ISBLK | |
53 #undef S_ISCHR | |
54 #undef S_ISDIR | |
55 #undef S_ISFIFO | |
56 #undef S_ISLNK | |
57 #undef S_ISMPB | |
58 #undef S_ISMPC | |
59 #undef S_ISNWK | |
60 #undef S_ISREG | |
61 #undef S_ISSOCK | |
62 #endif /* STAT_MACROS_BROKEN. */ | |
63 | |
64 #if !defined(S_ISBLK) && defined(S_IFBLK) | |
65 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) | |
66 #endif | |
67 #if !defined(S_ISCHR) && defined(S_IFCHR) | |
68 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) | |
69 #endif | |
70 #if !defined(S_ISDIR) && defined(S_IFDIR) | |
71 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) | |
72 #endif | |
73 #if !defined(S_ISREG) && defined(S_IFREG) | |
74 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) | |
75 #endif | |
76 #if !defined(S_ISFIFO) && defined(S_IFIFO) | |
77 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) | |
78 #endif | |
79 #if !defined(S_ISLNK) && defined(S_IFLNK) | |
80 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) | |
81 #endif | |
82 #if !defined(S_ISSOCK) && defined(S_IFSOCK) | |
83 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) | |
84 #endif | |
85 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */ | |
86 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB) | |
87 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC) | |
88 #endif | |
89 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */ | |
90 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) | |
91 #endif | |
92 | |
93 void mode_string (); | |
94 static char ftypelet (); | |
95 static void rwx (); | |
96 static void setst (); | |
97 | |
98 /* filemodestring - fill in string STR with an ls-style ASCII | |
99 representation of the st_mode field of file stats block STATP. | |
100 10 characters are stored in STR; no terminating null is added. | |
101 The characters stored in STR are: | |
102 | |
103 0 File type. 'd' for directory, 'c' for character | |
104 special, 'b' for block special, 'm' for multiplex, | |
105 'l' for symbolic link, 's' for socket, 'p' for fifo, | |
106 '-' for regular, '?' for any other file type | |
107 | |
108 1 'r' if the owner may read, '-' otherwise. | |
109 | |
110 2 'w' if the owner may write, '-' otherwise. | |
111 | |
112 3 'x' if the owner may execute, 's' if the file is | |
113 set-user-id, '-' otherwise. | |
114 'S' if the file is set-user-id, but the execute | |
115 bit isn't set. | |
116 | |
117 4 'r' if group members may read, '-' otherwise. | |
118 | |
119 5 'w' if group members may write, '-' otherwise. | |
120 | |
121 6 'x' if group members may execute, 's' if the file is | |
122 set-group-id, '-' otherwise. | |
123 'S' if it is set-group-id but not executable. | |
124 | |
125 7 'r' if any user may read, '-' otherwise. | |
126 | |
127 8 'w' if any user may write, '-' otherwise. | |
128 | |
129 9 'x' if any user may execute, 't' if the file is "sticky" | |
130 (will be retained in swap space after execution), '-' | |
131 otherwise. | |
132 'T' if the file is sticky but not executable. */ | |
133 | |
134 void | |
135 filemodestring (statp, str) | |
136 struct stat *statp; | |
137 char *str; | |
138 { | |
139 mode_string (statp->st_mode, str); | |
140 } | |
141 | |
142 /* Like filemodestring, but only the relevant part of the `struct stat' | |
143 is given as an argument. */ | |
144 | |
145 void | |
146 mode_string (mode, str) | |
147 unsigned short mode; | |
148 char *str; | |
149 { | |
150 str[0] = ftypelet ((long) mode); | |
151 rwx ((mode & 0700) << 0, &str[1]); | |
152 rwx ((mode & 0070) << 3, &str[4]); | |
153 rwx ((mode & 0007) << 6, &str[7]); | |
154 setst (mode, str); | |
155 } | |
156 | |
157 /* Return a character indicating the type of file described by | |
158 file mode BITS: | |
159 'd' for directories | |
160 'b' for block special files | |
161 'c' for character special files | |
162 'm' for multiplexor files | |
163 'l' for symbolic links | |
164 's' for sockets | |
165 'p' for fifos | |
166 '-' for regular files | |
167 '?' for any other file type. */ | |
168 | |
169 static char | |
170 ftypelet (bits) | |
171 long bits; | |
172 { | |
173 #ifdef S_ISBLK | |
174 if (S_ISBLK (bits)) | |
175 return 'b'; | |
176 #endif | |
177 if (S_ISCHR (bits)) | |
178 return 'c'; | |
179 if (S_ISDIR (bits)) | |
180 return 'd'; | |
181 if (S_ISREG (bits)) | |
182 return '-'; | |
183 #ifdef S_ISFIFO | |
184 if (S_ISFIFO (bits)) | |
185 return 'p'; | |
186 #endif | |
187 #ifdef S_ISLNK | |
188 if (S_ISLNK (bits)) | |
189 return 'l'; | |
190 #endif | |
191 #ifdef S_ISSOCK | |
192 if (S_ISSOCK (bits)) | |
193 return 's'; | |
194 #endif | |
195 #ifdef S_ISMPC | |
196 if (S_ISMPC (bits)) | |
197 return 'm'; | |
198 #endif | |
199 #ifdef S_ISNWK | |
200 if (S_ISNWK (bits)) | |
201 return 'n'; | |
202 #endif | |
203 return '?'; | |
204 } | |
205 | |
206 /* Look at read, write, and execute bits in BITS and set | |
207 flags in CHARS accordingly. */ | |
208 | |
209 static void | |
210 rwx (bits, chars) | |
211 unsigned short bits; | |
212 char *chars; | |
213 { | |
214 chars[0] = (bits & S_IRUSR) ? 'r' : '-'; | |
215 chars[1] = (bits & S_IWUSR) ? 'w' : '-'; | |
216 chars[2] = (bits & S_IXUSR) ? 'x' : '-'; | |
217 } | |
218 | |
219 /* Set the 's' and 't' flags in file attributes string CHARS, | |
220 according to the file mode BITS. */ | |
221 | |
222 static void | |
223 setst (bits, chars) | |
224 unsigned short bits; | |
225 char *chars; | |
226 { | |
227 #ifdef S_ISUID | |
228 if (bits & S_ISUID) | |
229 { | |
230 if (chars[3] != 'x') | |
231 /* Set-uid, but not executable by owner. */ | |
232 chars[3] = 'S'; | |
233 else | |
234 chars[3] = 's'; | |
235 } | |
236 #endif | |
237 #ifdef S_ISGID | |
238 if (bits & S_ISGID) | |
239 { | |
240 if (chars[6] != 'x') | |
241 /* Set-gid, but not executable by group. */ | |
242 chars[6] = 'S'; | |
243 else | |
244 chars[6] = 's'; | |
245 } | |
246 #endif | |
247 #ifdef S_ISVTX | |
248 if (bits & S_ISVTX) | |
249 { | |
250 if (chars[9] != 'x') | |
251 /* Sticky, but not executable by others. */ | |
252 chars[9] = 'T'; | |
253 else | |
254 chars[9] = 't'; | |
255 } | |
256 #endif | |
257 } | |
52401 | 258 |
259 /* arch-tag: 4340830c-15a5-47d2-b45f-1d43c45a91bb | |
260 (do not change this comment) */ |