comparison liboctave/filemode.c @ 11512:e4e82740e9cd

prototype fixes for C language files
author John W. Eaton <jwe@octave.org>
date Thu, 13 Jan 2011 07:23:36 -0500
parents 42d098307c30
children
comparison
equal deleted inserted replaced
11511:8837a42205d3 11512:e4e82740e9cd
18 18
19 #ifdef HAVE_CONFIG_H 19 #ifdef HAVE_CONFIG_H
20 #include <config.h> 20 #include <config.h>
21 #endif 21 #endif
22 22
23 #include <sys/types.h> 23 #include "filemode.h"
24 #include <sys/stat.h>
25 24
26 #if !S_IRUSR 25 #if !S_IRUSR
27 # if S_IREAD 26 # if S_IREAD
28 # define S_IRUSR S_IREAD 27 # define S_IRUSR S_IREAD
29 # else 28 # else
87 #endif 86 #endif
88 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */ 87 #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
89 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) 88 #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
90 #endif 89 #endif
91 90
92 void mode_string ();
93 static char ftypelet ();
94 static void rwx ();
95 static void setst ();
96
97 /* filemodestring - fill in string STR with an ls-style ASCII
98 representation of the st_mode field of file stats block STATP.
99 10 characters are stored in STR; no terminating null is added.
100 The characters stored in STR are:
101
102 0 File type. 'd' for directory, 'c' for character
103 special, 'b' for block special, 'm' for multiplex,
104 'l' for symbolic link, 's' for socket, 'p' for fifo,
105 '-' for regular, '?' for any other file type
106
107 1 'r' if the owner may read, '-' otherwise.
108
109 2 'w' if the owner may write, '-' otherwise.
110
111 3 'x' if the owner may execute, 's' if the file is
112 set-user-id, '-' otherwise.
113 'S' if the file is set-user-id, but the execute
114 bit isn't set.
115
116 4 'r' if group members may read, '-' otherwise.
117
118 5 'w' if group members may write, '-' otherwise.
119
120 6 'x' if group members may execute, 's' if the file is
121 set-group-id, '-' otherwise.
122 'S' if it is set-group-id but not executable.
123
124 7 'r' if any user may read, '-' otherwise.
125
126 8 'w' if any user may write, '-' otherwise.
127
128 9 'x' if any user may execute, 't' if the file is "sticky"
129 (will be retained in swap space after execution), '-'
130 otherwise.
131 'T' if the file is sticky but not executable. */
132
133 void
134 filemodestring (statp, str)
135 struct stat *statp;
136 char *str;
137 {
138 mode_string (statp->st_mode, str);
139 }
140
141 /* Like filemodestring, but only the relevant part of the `struct stat'
142 is given as an argument. */
143
144 void
145 mode_string (mode, str)
146 unsigned short mode;
147 char *str;
148 {
149 str[0] = ftypelet ((long) mode);
150 rwx ((mode & 0700) << 0, &str[1]);
151 rwx ((mode & 0070) << 3, &str[4]);
152 rwx ((mode & 0007) << 6, &str[7]);
153 setst (mode, str);
154 }
155
156 /* Return a character indicating the type of file described by 91 /* Return a character indicating the type of file described by
157 file mode BITS: 92 file mode BITS:
158 'd' for directories 93 'd' for directories
159 'b' for block special files 94 'b' for block special files
160 'c' for character special files 95 'c' for character special files
164 'p' for fifos 99 'p' for fifos
165 '-' for regular files 100 '-' for regular files
166 '?' for any other file type. */ 101 '?' for any other file type. */
167 102
168 static char 103 static char
169 ftypelet (bits) 104 ftypelet (long bits)
170 long bits;
171 { 105 {
172 #ifdef S_ISBLK 106 #ifdef S_ISBLK
173 if (S_ISBLK (bits)) 107 if (S_ISBLK (bits))
174 return 'b'; 108 return 'b';
175 #endif 109 #endif
204 138
205 /* Look at read, write, and execute bits in BITS and set 139 /* Look at read, write, and execute bits in BITS and set
206 flags in CHARS accordingly. */ 140 flags in CHARS accordingly. */
207 141
208 static void 142 static void
209 rwx (bits, chars) 143 rwx (unsigned short bits, char *chars)
210 unsigned short bits;
211 char *chars;
212 { 144 {
213 chars[0] = (bits & S_IRUSR) ? 'r' : '-'; 145 chars[0] = (bits & S_IRUSR) ? 'r' : '-';
214 chars[1] = (bits & S_IWUSR) ? 'w' : '-'; 146 chars[1] = (bits & S_IWUSR) ? 'w' : '-';
215 chars[2] = (bits & S_IXUSR) ? 'x' : '-'; 147 chars[2] = (bits & S_IXUSR) ? 'x' : '-';
216 } 148 }
217 149
218 /* Set the 's' and 't' flags in file attributes string CHARS, 150 /* Set the 's' and 't' flags in file attributes string CHARS,
219 according to the file mode BITS. */ 151 according to the file mode BITS. */
220 152
221 static void 153 static void
222 setst (bits, chars) 154 setst (unsigned short bits, char *chars)
223 unsigned short bits;
224 char *chars;
225 { 155 {
226 #ifdef S_ISUID 156 #ifdef S_ISUID
227 if (bits & S_ISUID) 157 if (bits & S_ISUID)
228 { 158 {
229 if (chars[3] != 'x') 159 if (chars[3] != 'x')
252 else 182 else
253 chars[9] = 't'; 183 chars[9] = 't';
254 } 184 }
255 #endif 185 #endif
256 } 186 }
187
188 /* Like filemodestring, but only the relevant part of the `struct stat'
189 is given as an argument. */
190
191 void
192 mode_string (unsigned short mode, char *str)
193 {
194 str[0] = ftypelet ((long) mode);
195 rwx ((mode & 0700) << 0, &str[1]);
196 rwx ((mode & 0070) << 3, &str[4]);
197 rwx ((mode & 0007) << 6, &str[7]);
198 setst (mode, str);
199 }
200
201 /* filemodestring - fill in string STR with an ls-style ASCII
202 representation of the st_mode field of file stats block STATP.
203 10 characters are stored in STR; no terminating null is added.
204 The characters stored in STR are:
205
206 0 File type. 'd' for directory, 'c' for character
207 special, 'b' for block special, 'm' for multiplex,
208 'l' for symbolic link, 's' for socket, 'p' for fifo,
209 '-' for regular, '?' for any other file type
210
211 1 'r' if the owner may read, '-' otherwise.
212
213 2 'w' if the owner may write, '-' otherwise.
214
215 3 'x' if the owner may execute, 's' if the file is
216 set-user-id, '-' otherwise.
217 'S' if the file is set-user-id, but the execute
218 bit isn't set.
219
220 4 'r' if group members may read, '-' otherwise.
221
222 5 'w' if group members may write, '-' otherwise.
223
224 6 'x' if group members may execute, 's' if the file is
225 set-group-id, '-' otherwise.
226 'S' if it is set-group-id but not executable.
227
228 7 'r' if any user may read, '-' otherwise.
229
230 8 'w' if any user may write, '-' otherwise.
231
232 9 'x' if any user may execute, 't' if the file is "sticky"
233 (will be retained in swap space after execution), '-'
234 otherwise.
235 'T' if the file is sticky but not executable. */
236
237 void
238 filemodestring (struct stat *statp, char *str)
239 {
240 mode_string (statp->st_mode, str);
241 }