/[eiffelstudio]/FreeELKS/trunk/library/kernel/unix_file_info.e
ViewVC logotype

Contents of /FreeELKS/trunk/library/kernel/unix_file_info.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91424 - (show annotations)
Tue Oct 26 18:39:32 2004 UTC (15 years, 2 months ago) by manus_eiffel
File size: 7263 byte(s)
Initial revision

1 indexing
2
3 description:
4 "Internal file information"
5
6 status: "See notice at end of class"
7 date: "$Date$"
8 revision: "$Revision$"
9
10 class UNIX_FILE_INFO inherit
11
12 TO_SPECIAL [CHARACTER]
13 rename
14 area as buffered_file_info,
15 make_area as make_buffered_file_info
16 end
17
18 create
19
20 make
21
22 feature -- Initialization
23
24 make is
25 -- Creation procedure
26 do
27 make_buffered_file_info (stat_size)
28 end
29
30 feature -- Access
31
32 protection: INTEGER is
33 -- Protection mode of file (12 lower bits)
34 do
35 Result := file_info ($buffered_file_info, 0)
36 end
37
38 type: INTEGER is
39 -- File type (4 bits, 12 lowest bits zeroed)
40 do
41 Result := file_info ($buffered_file_info, 11)
42 end
43
44 inode: INTEGER is
45 -- Inode number
46 do
47 Result := file_info ($buffered_file_info, 1)
48 end
49
50 size: INTEGER is
51 -- File size, in bytes
52 do
53 Result := file_info ($buffered_file_info, 6)
54 end
55
56 user_id: INTEGER is
57 -- UID of the file owner
58 do
59 Result := file_info ($buffered_file_info, 4)
60 end
61
62 group_id: INTEGER is
63 -- GID of the file
64 do
65 Result := file_info ($buffered_file_info, 5)
66 end
67
68 date: INTEGER is
69 -- Last modification date
70 do
71 Result := file_info ($buffered_file_info, 7)
72 end
73
74 access_date: INTEGER is
75 -- Date of last access
76 do
77 Result := file_info ($buffered_file_info, 8)
78 end
79
80 change_date: INTEGER is
81 -- Date of last status change
82 do
83 Result := file_info ($buffered_file_info, 9)
84 end
85
86 device: INTEGER is
87 -- Device number on which inode resides
88 do
89 Result := file_info ($buffered_file_info, 2)
90 end
91
92 device_type: INTEGER is
93 -- Device type on which inode resides
94 do
95 Result := file_info ($buffered_file_info, 3)
96 end
97
98 links: INTEGER is
99 -- Number of links
100 do
101 Result := file_info ($buffered_file_info, 10)
102 end
103
104 owner_name: STRING is
105 -- Name of the file owner, if available from /etc/passwd.
106 -- Otherwise, the UID
107 do
108 Result := file_owner (user_id)
109 end -- owner_name
110
111 group_name: STRING is
112 -- Name of the file group, if available from /etc/group.
113 -- Otherwise, the GID
114 do
115 Result := file_group (group_id)
116 end -- owner_name
117
118 file_name: STRING
119 -- File name to which information applies.
120
121 feature -- Status report
122
123 is_plain: BOOLEAN is
124 -- Is file a plain file?
125 do
126 Result := file_info ($buffered_file_info, 13) /= 0
127 end
128
129 is_device: BOOLEAN is
130 -- Is file a device?
131 do
132 Result := file_info ($buffered_file_info, 14) /= 0
133 end
134
135 is_directory: BOOLEAN is
136 -- Is file a directory?
137 do
138 Result := file_info ($buffered_file_info, 12) /= 0
139 end
140
141 is_symlink: BOOLEAN is
142 -- Is file a symbolic link?
143 do
144 Result := file_info ($buffered_file_info, 18) /= 0
145 end
146
147 is_fifo: BOOLEAN is
148 -- Is file a named pipe?
149 do
150 Result := file_info ($buffered_file_info, 17) /= 0
151 end
152
153 is_socket: BOOLEAN is
154 -- Is file a named socket?
155 do
156 Result := file_info ($buffered_file_info, 19) /= 0
157 end
158
159 is_block: BOOLEAN is
160 -- Is file a device block special file?
161 do
162 Result := file_info ($buffered_file_info, 16) /= 0
163 end
164
165 is_character: BOOLEAN is
166 -- Is file a character block special file?
167 do
168 Result := file_info ($buffered_file_info, 15) /= 0
169 end
170
171 is_readable: BOOLEAN is
172 -- Is file readable by effective UID?
173 do
174 Result := file_eaccess ($buffered_file_info, 0)
175 end
176
177 is_writable: BOOLEAN is
178 -- Is file writable by effective UID?
179 do
180 Result := file_eaccess ($buffered_file_info, 1)
181 end
182
183 is_executable: BOOLEAN is
184 -- Is file executable by effective UID?
185 do
186 Result := file_eaccess ($buffered_file_info, 2)
187 end
188
189 is_setuid: BOOLEAN is
190 -- Is file setuid?
191 do
192 Result := file_eaccess ($buffered_file_info, 3)
193 end
194
195 is_setgid: BOOLEAN is
196 -- Is file setgid?
197 do
198 Result := file_eaccess ($buffered_file_info, 4)
199 end
200
201 is_sticky: BOOLEAN is
202 -- Is file sticky?
203 do
204 Result := file_eaccess ($buffered_file_info, 5)
205 end
206
207 is_owner: BOOLEAN is
208 -- Is file owned by effective UID?
209 do
210 Result := file_eaccess ($buffered_file_info, 6)
211 end
212
213 is_access_owner: BOOLEAN is
214 -- Is file owned by real UID?
215 do
216 Result := file_eaccess ($buffered_file_info, 7)
217 end
218
219 is_access_readable: BOOLEAN is
220 -- Is file readable by real UID?
221 local
222 ext_name: ANY
223 do
224 ext_name := file_name.to_c
225 Result := file_access ($ext_name, 3)
226 end
227
228 is_access_writable: BOOLEAN is
229 -- Is file writable by real UID?
230 local
231 ext_name: ANY
232 do
233 ext_name := file_name.to_c
234 Result := file_access ($ext_name, 2)
235 end
236
237 is_access_executable: BOOLEAN is
238 -- Is file executable by real UID?
239 local
240 ext_name: ANY
241 do
242 ext_name := file_name.to_c
243 Result := file_access ($ext_name, 1)
244 end
245
246 feature -- Element change
247
248 update (f_name: STRING) is
249 -- Update information buffer: fill it in with information
250 -- from the inode of `f_name'.
251 local
252 ext_name: ANY
253 do
254 ext_name := f_name.to_c
255 file_stat ($ext_name, $buffered_file_info)
256 -- Do not duplicate the file name. That way, if the file is
257 -- renamed, the name here will change accordingly and access()
258 -- based calls will continue to work properly.
259 file_name := f_name
260 end -- update
261
262 feature {NONE} -- Implementation
263
264 stat_size: INTEGER is
265 -- Get size of 'struct stat' (in bytes)
266 external
267 "C | %"eif_file.h%""
268 end
269
270 file_stat (name, stat_buf: POINTER) is
271 -- Get information from file `name' into `stat_buf'
272 external
273 "C (char *, struct stat *) | %"eif_file.h%""
274 end
275
276 file_access (f_name: POINTER; which: INTEGER): BOOLEAN is
277 -- Perform access test `which' on `f_name' using real ID.
278 external
279 "C (char *, EIF_INTEGER): EIF_BOOLEAN | %"eif_file.h%""
280 end
281
282 file_eaccess (stat_buf: POINTER; which: INTEGER): BOOLEAN is
283 -- Perform access tests using effective ID.
284 external
285 "C (struct stat *, int): EIF_BOOLEAN | %"eif_file.h%""
286 end
287
288 file_info (stat_buf: POINTER; which: INTEGER): INTEGER is
289 -- Extract information `which' from information buffer
290 external
291 "C (struct stat *, int): EIF_INTEGER | %"eif_file.h%""
292 end
293
294 file_owner (uid: INTEGER): STRING is
295 -- Convert UID to login name if possible
296 external
297 "C signature (int): EIF_REFERENCE use %"eif_file.h%""
298 end
299
300 file_group (gid: INTEGER): STRING is
301 -- Convert GID to group name if possible
302 external
303 "C signature (int): EIF_REFERENCE use %"eif_file.h%""
304 end
305
306 indexing
307
308 library: "[
309 EiffelBase: Library of reusable components for Eiffel.
310 ]"
311
312 status: "[
313 Copyright 1986-2001 Interactive Software Engineering (ISE).
314 For ISE customers the original versions are an ISE product
315 covered by the ISE Eiffel license and support agreements.
316 ]"
317
318 license: "[
319 EiffelBase may now be used by anyone as FREE SOFTWARE to
320 develop any product, public-domain or commercial, without
321 payment to ISE, under the terms of the ISE Free Eiffel Library
322 License (IFELL) at http://eiffel.com/products/base/license.html.
323 ]"
324
325 source: "[
326 Interactive Software Engineering Inc.
327 ISE Building
328 360 Storke Road, Goleta, CA 93117 USA
329 Telephone 805-685-1006, Fax 805-685-6869
330 Electronic mail <info@eiffel.com>
331 Customer support http://support.eiffel.com
332 ]"
333
334 info: "[
335 For latest info see award-winning pages: http://eiffel.com
336 ]"
337
338 end -- class UNIX_FILE_INFO
339
340
341

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23