annotate src/filemode.c @ 109303:c17b03e52a4a

Merge changes from emacs-23 branch.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 10 Jul 2010 15:01:01 -0400
parents 76e072dbe342
children 417b1e4d63cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
1 /* filemode.c -- make a string describing file modes
75227
e90d04cd455a Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents: 68651
diff changeset
2 Copyright (C) 1985, 1990, 1993, 2001, 2002, 2003, 2004,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100951
diff changeset
3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
4
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
78260
922696f363b0 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75227
diff changeset
7 the Free Software Foundation; either version 3, or (at your option)
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
8 any later version.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
9
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
13 GNU General Public License for more details.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
14
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
16 along with this program; if not, write to the Free Software
64084
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
18 USA. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
19
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
20 #include <config.h>
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
21 #include <sys/types.h>
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
22 #include <sys/stat.h>
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
23
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
24 #if !S_IRUSR
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
25 # if S_IREAD
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
26 # define S_IRUSR S_IREAD
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
27 # else
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
28 # define S_IRUSR 00400
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
29 # endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
30 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
31
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
32 #if !S_IWUSR
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
33 # if S_IWRITE
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
34 # define S_IWUSR S_IWRITE
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
35 # else
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
36 # define S_IWUSR 00200
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
37 # endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
38 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
39
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
40 #if !S_IXUSR
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
41 # if S_IEXEC
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
42 # define S_IXUSR S_IEXEC
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
43 # else
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
44 # define S_IXUSR 00100
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
45 # endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
46 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
47
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
48 #ifdef STAT_MACROS_BROKEN
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
49 #undef S_ISBLK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
50 #undef S_ISCHR
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
51 #undef S_ISDIR
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
52 #undef S_ISFIFO
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
53 #undef S_ISLNK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
54 #undef S_ISMPB
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
55 #undef S_ISMPC
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
56 #undef S_ISNWK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
57 #undef S_ISREG
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
58 #undef S_ISSOCK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
59 #endif /* STAT_MACROS_BROKEN. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
60
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
61 #if !defined(S_ISBLK) && defined(S_IFBLK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
62 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
63 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
64 #if !defined(S_ISCHR) && defined(S_IFCHR)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
65 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
66 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
67 #if !defined(S_ISDIR) && defined(S_IFDIR)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
68 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
69 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
70 #if !defined(S_ISREG) && defined(S_IFREG)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
71 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
72 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
73 #if !defined(S_ISFIFO) && defined(S_IFIFO)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
74 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
75 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
76 #if !defined(S_ISLNK) && defined(S_IFLNK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
77 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
78 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
79 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
80 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
81 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
82 #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
83 #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
84 #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
85 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
86 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
87 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
88 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
89
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
90 void mode_string (short unsigned int mode, char *str);
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
91 static char ftypelet (long int bits);
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
92 static void rwx (short unsigned int bits, char *chars);
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
93 static void setst (short unsigned int bits, char *chars);
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
94
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
95 /* filemodestring - fill in string STR with an ls-style ASCII
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
96 representation of the st_mode field of file stats block STATP.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
97 10 characters are stored in STR; no terminating null is added.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
98 The characters stored in STR are:
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
99
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
100 0 File type. 'd' for directory, 'c' for character
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
101 special, 'b' for block special, 'm' for multiplex,
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
102 'l' for symbolic link, 's' for socket, 'p' for fifo,
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
103 '-' for regular, '?' for any other file type
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
104
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
105 1 'r' if the owner may read, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
106
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
107 2 'w' if the owner may write, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
108
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
109 3 'x' if the owner may execute, 's' if the file is
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
110 set-user-id, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
111 'S' if the file is set-user-id, but the execute
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
112 bit isn't set.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
113
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
114 4 'r' if group members may read, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
115
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
116 5 'w' if group members may write, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
117
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
118 6 'x' if group members may execute, 's' if the file is
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
119 set-group-id, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
120 'S' if it is set-group-id but not executable.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
121
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
122 7 'r' if any user may read, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
123
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
124 8 'w' if any user may write, '-' otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
125
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
126 9 'x' if any user may execute, 't' if the file is "sticky"
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
127 (will be retained in swap space after execution), '-'
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
128 otherwise.
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
129 'T' if the file is sticky but not executable. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
130
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
131 void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
132 filemodestring (struct stat *statp, char *str)
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
133 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
134 mode_string (statp->st_mode, str);
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
135 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
136
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
137 /* Like filemodestring, but only the relevant part of the `struct stat'
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
138 is given as an argument. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
139
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
140 void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
141 mode_string (short unsigned int mode, char *str)
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
142 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
143 str[0] = ftypelet ((long) mode);
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
144 rwx ((mode & 0700) << 0, &str[1]);
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
145 rwx ((mode & 0070) << 3, &str[4]);
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
146 rwx ((mode & 0007) << 6, &str[7]);
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
147 setst (mode, str);
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
148 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
149
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
150 /* Return a character indicating the type of file described by
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
151 file mode BITS:
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
152 'd' for directories
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
153 'b' for block special files
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
154 'c' for character special files
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
155 'm' for multiplexor files
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
156 'l' for symbolic links
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
157 's' for sockets
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
158 'p' for fifos
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
159 '-' for regular files
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
160 '?' for any other file type. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
161
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
162 static char
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
163 ftypelet (long int bits)
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
164 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
165 #ifdef S_ISBLK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
166 if (S_ISBLK (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
167 return 'b';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
168 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
169 if (S_ISCHR (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
170 return 'c';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
171 if (S_ISDIR (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
172 return 'd';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
173 if (S_ISREG (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
174 return '-';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
175 #ifdef S_ISFIFO
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
176 if (S_ISFIFO (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
177 return 'p';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
178 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
179 #ifdef S_ISLNK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
180 if (S_ISLNK (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
181 return 'l';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
182 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
183 #ifdef S_ISSOCK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
184 if (S_ISSOCK (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
185 return 's';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
186 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
187 #ifdef S_ISMPC
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
188 if (S_ISMPC (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
189 return 'm';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
190 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
191 #ifdef S_ISNWK
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
192 if (S_ISNWK (bits))
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
193 return 'n';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
194 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
195 return '?';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
196 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
197
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
198 /* Look at read, write, and execute bits in BITS and set
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
199 flags in CHARS accordingly. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
200
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
201 static void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
202 rwx (short unsigned int bits, char *chars)
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
203 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
204 chars[0] = (bits & S_IRUSR) ? 'r' : '-';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
205 chars[1] = (bits & S_IWUSR) ? 'w' : '-';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
206 chars[2] = (bits & S_IXUSR) ? 'x' : '-';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
207 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
208
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
209 /* Set the 's' and 't' flags in file attributes string CHARS,
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
210 according to the file mode BITS. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
211
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
212 static void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 106815
diff changeset
213 setst (short unsigned int bits, char *chars)
25843
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
214 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
215 #ifdef S_ISUID
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
216 if (bits & S_ISUID)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
217 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
218 if (chars[3] != 'x')
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
219 /* Set-uid, but not executable by owner. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
220 chars[3] = 'S';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
221 else
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
222 chars[3] = 's';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
223 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
224 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
225 #ifdef S_ISGID
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
226 if (bits & S_ISGID)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
227 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
228 if (chars[6] != 'x')
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
229 /* Set-gid, but not executable by group. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
230 chars[6] = 'S';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
231 else
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
232 chars[6] = 's';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
233 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
234 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
235 #ifdef S_ISVTX
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
236 if (bits & S_ISVTX)
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
237 {
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
238 if (chars[9] != 'x')
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
239 /* Sticky, but not executable by others. */
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
240 chars[9] = 'T';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
241 else
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
242 chars[9] = 't';
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
243 }
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
244 #endif
18e524802887 #ecrt0.c
Dave Love <fx@gnu.org>
parents:
diff changeset
245 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 25843
diff changeset
246
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 25843
diff changeset
247 /* arch-tag: 4340830c-15a5-47d2-b45f-1d43c45a91bb
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 25843
diff changeset
248 (do not change this comment) */