1 | n/a | /* stat.h interface |
---|
2 | n/a | * |
---|
3 | n/a | * The module defines all S_IF*, S_I*, UF_*, SF_* and ST_* constants to |
---|
4 | n/a | * sensible default values as well as defines S_IS*() macros in order to keep |
---|
5 | n/a | * backward compatibility with the old stat.py module. |
---|
6 | n/a | * |
---|
7 | n/a | * New constants and macros such as S_IFDOOR / S_ISDOOR() are always defined |
---|
8 | n/a | * as int 0. |
---|
9 | n/a | * |
---|
10 | n/a | * NOTE: POSIX only defines the values of the S_I* permission bits. |
---|
11 | n/a | * |
---|
12 | n/a | */ |
---|
13 | n/a | |
---|
14 | n/a | #define PY_SSIZE_T_CLEAN |
---|
15 | n/a | #include "Python.h" |
---|
16 | n/a | |
---|
17 | n/a | #ifdef __cplusplus |
---|
18 | n/a | extern "C" { |
---|
19 | n/a | #endif |
---|
20 | n/a | |
---|
21 | n/a | #ifdef HAVE_SYS_TYPES_H |
---|
22 | n/a | #include <sys/types.h> |
---|
23 | n/a | #endif /* HAVE_SYS_TYPES_H */ |
---|
24 | n/a | |
---|
25 | n/a | #ifdef HAVE_SYS_STAT_H |
---|
26 | n/a | #include <sys/stat.h> |
---|
27 | n/a | #endif /* HAVE_SYS_STAT_H */ |
---|
28 | n/a | |
---|
29 | n/a | #ifdef MS_WINDOWS |
---|
30 | n/a | #include <windows.h> |
---|
31 | n/a | typedef unsigned short mode_t; |
---|
32 | n/a | |
---|
33 | n/a | /* FILE_ATTRIBUTE_INTEGRITY_STREAM and FILE_ATTRIBUTE_NO_SCRUB_DATA |
---|
34 | n/a | are not present in VC2010, so define them manually */ |
---|
35 | n/a | #ifndef FILE_ATTRIBUTE_INTEGRITY_STREAM |
---|
36 | n/a | # define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x8000 |
---|
37 | n/a | #endif |
---|
38 | n/a | |
---|
39 | n/a | #ifndef FILE_ATTRIBUTE_NO_SCRUB_DATA |
---|
40 | n/a | # define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x20000 |
---|
41 | n/a | #endif |
---|
42 | n/a | |
---|
43 | n/a | #endif /* MS_WINDOWS */ |
---|
44 | n/a | |
---|
45 | n/a | /* From Python's stat.py */ |
---|
46 | n/a | #ifndef S_IMODE |
---|
47 | n/a | # define S_IMODE 07777 |
---|
48 | n/a | #endif |
---|
49 | n/a | |
---|
50 | n/a | /* S_IFXXX constants (file types) |
---|
51 | n/a | * |
---|
52 | n/a | * Only the names are defined by POSIX but not their value. All common file |
---|
53 | n/a | * types seems to have the same numeric value on all platforms, though. |
---|
54 | n/a | * |
---|
55 | n/a | * pyport.h guarantees S_IFMT, S_IFDIR, S_IFCHR, S_IFREG and S_IFLNK |
---|
56 | n/a | */ |
---|
57 | n/a | |
---|
58 | n/a | #ifndef S_IFBLK |
---|
59 | n/a | # define S_IFBLK 0060000 |
---|
60 | n/a | #endif |
---|
61 | n/a | |
---|
62 | n/a | #ifndef S_IFIFO |
---|
63 | n/a | # define S_IFIFO 0010000 |
---|
64 | n/a | #endif |
---|
65 | n/a | |
---|
66 | n/a | #ifndef S_IFSOCK |
---|
67 | n/a | # define S_IFSOCK 0140000 |
---|
68 | n/a | #endif |
---|
69 | n/a | |
---|
70 | n/a | #ifndef S_IFDOOR |
---|
71 | n/a | # define S_IFDOOR 0 |
---|
72 | n/a | #endif |
---|
73 | n/a | |
---|
74 | n/a | #ifndef S_IFPORT |
---|
75 | n/a | # define S_IFPORT 0 |
---|
76 | n/a | #endif |
---|
77 | n/a | |
---|
78 | n/a | #ifndef S_IFWHT |
---|
79 | n/a | # define S_IFWHT 0 |
---|
80 | n/a | #endif |
---|
81 | n/a | |
---|
82 | n/a | |
---|
83 | n/a | /* S_ISXXX() |
---|
84 | n/a | * pyport.h defines S_ISDIR(), S_ISREG() and S_ISCHR() |
---|
85 | n/a | */ |
---|
86 | n/a | |
---|
87 | n/a | #ifndef S_ISBLK |
---|
88 | n/a | # define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) |
---|
89 | n/a | #endif |
---|
90 | n/a | |
---|
91 | n/a | #ifndef S_ISFIFO |
---|
92 | n/a | # define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) |
---|
93 | n/a | #endif |
---|
94 | n/a | |
---|
95 | n/a | #ifndef S_ISLNK |
---|
96 | n/a | # define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) |
---|
97 | n/a | #endif |
---|
98 | n/a | |
---|
99 | n/a | #ifndef S_ISSOCK |
---|
100 | n/a | # define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) |
---|
101 | n/a | #endif |
---|
102 | n/a | |
---|
103 | n/a | #ifndef S_ISDOOR |
---|
104 | n/a | # define S_ISDOOR(mode) 0 |
---|
105 | n/a | #endif |
---|
106 | n/a | |
---|
107 | n/a | #ifndef S_ISPORT |
---|
108 | n/a | # define S_ISPORT(mode) 0 |
---|
109 | n/a | #endif |
---|
110 | n/a | |
---|
111 | n/a | #ifndef S_ISWHT |
---|
112 | n/a | # define S_ISWHT(mode) 0 |
---|
113 | n/a | #endif |
---|
114 | n/a | |
---|
115 | n/a | |
---|
116 | n/a | /* S_I* file permission |
---|
117 | n/a | * |
---|
118 | n/a | * The permission bit value are defined by POSIX standards. |
---|
119 | n/a | */ |
---|
120 | n/a | #ifndef S_ISUID |
---|
121 | n/a | # define S_ISUID 04000 |
---|
122 | n/a | #endif |
---|
123 | n/a | |
---|
124 | n/a | #ifndef S_ISGID |
---|
125 | n/a | # define S_ISGID 02000 |
---|
126 | n/a | #endif |
---|
127 | n/a | |
---|
128 | n/a | /* what is S_ENFMT? */ |
---|
129 | n/a | #ifndef S_ENFMT |
---|
130 | n/a | # define S_ENFMT S_ISGID |
---|
131 | n/a | #endif |
---|
132 | n/a | |
---|
133 | n/a | #ifndef S_ISVTX |
---|
134 | n/a | # define S_ISVTX 01000 |
---|
135 | n/a | #endif |
---|
136 | n/a | |
---|
137 | n/a | #ifndef S_IREAD |
---|
138 | n/a | # define S_IREAD 00400 |
---|
139 | n/a | #endif |
---|
140 | n/a | |
---|
141 | n/a | #ifndef S_IWRITE |
---|
142 | n/a | # define S_IWRITE 00200 |
---|
143 | n/a | #endif |
---|
144 | n/a | |
---|
145 | n/a | #ifndef S_IEXEC |
---|
146 | n/a | # define S_IEXEC 00100 |
---|
147 | n/a | #endif |
---|
148 | n/a | |
---|
149 | n/a | #ifndef S_IRWXU |
---|
150 | n/a | # define S_IRWXU 00700 |
---|
151 | n/a | #endif |
---|
152 | n/a | |
---|
153 | n/a | #ifndef S_IRUSR |
---|
154 | n/a | # define S_IRUSR 00400 |
---|
155 | n/a | #endif |
---|
156 | n/a | |
---|
157 | n/a | #ifndef S_IWUSR |
---|
158 | n/a | # define S_IWUSR 00200 |
---|
159 | n/a | #endif |
---|
160 | n/a | |
---|
161 | n/a | #ifndef S_IXUSR |
---|
162 | n/a | # define S_IXUSR 00100 |
---|
163 | n/a | #endif |
---|
164 | n/a | |
---|
165 | n/a | #ifndef S_IRWXG |
---|
166 | n/a | # define S_IRWXG 00070 |
---|
167 | n/a | #endif |
---|
168 | n/a | |
---|
169 | n/a | #ifndef S_IRGRP |
---|
170 | n/a | # define S_IRGRP 00040 |
---|
171 | n/a | #endif |
---|
172 | n/a | |
---|
173 | n/a | #ifndef S_IWGRP |
---|
174 | n/a | # define S_IWGRP 00020 |
---|
175 | n/a | #endif |
---|
176 | n/a | |
---|
177 | n/a | #ifndef S_IXGRP |
---|
178 | n/a | # define S_IXGRP 00010 |
---|
179 | n/a | #endif |
---|
180 | n/a | |
---|
181 | n/a | #ifndef S_IRWXO |
---|
182 | n/a | # define S_IRWXO 00007 |
---|
183 | n/a | #endif |
---|
184 | n/a | |
---|
185 | n/a | #ifndef S_IROTH |
---|
186 | n/a | # define S_IROTH 00004 |
---|
187 | n/a | #endif |
---|
188 | n/a | |
---|
189 | n/a | #ifndef S_IWOTH |
---|
190 | n/a | # define S_IWOTH 00002 |
---|
191 | n/a | #endif |
---|
192 | n/a | |
---|
193 | n/a | #ifndef S_IXOTH |
---|
194 | n/a | # define S_IXOTH 00001 |
---|
195 | n/a | #endif |
---|
196 | n/a | |
---|
197 | n/a | |
---|
198 | n/a | /* Names for file flags */ |
---|
199 | n/a | #ifndef UF_NODUMP |
---|
200 | n/a | # define UF_NODUMP 0x00000001 |
---|
201 | n/a | #endif |
---|
202 | n/a | |
---|
203 | n/a | #ifndef UF_IMMUTABLE |
---|
204 | n/a | # define UF_IMMUTABLE 0x00000002 |
---|
205 | n/a | #endif |
---|
206 | n/a | |
---|
207 | n/a | #ifndef UF_APPEND |
---|
208 | n/a | # define UF_APPEND 0x00000004 |
---|
209 | n/a | #endif |
---|
210 | n/a | |
---|
211 | n/a | #ifndef UF_OPAQUE |
---|
212 | n/a | # define UF_OPAQUE 0x00000008 |
---|
213 | n/a | #endif |
---|
214 | n/a | |
---|
215 | n/a | #ifndef UF_NOUNLINK |
---|
216 | n/a | # define UF_NOUNLINK 0x00000010 |
---|
217 | n/a | #endif |
---|
218 | n/a | |
---|
219 | n/a | #ifndef UF_COMPRESSED |
---|
220 | n/a | # define UF_COMPRESSED 0x00000020 |
---|
221 | n/a | #endif |
---|
222 | n/a | |
---|
223 | n/a | #ifndef UF_HIDDEN |
---|
224 | n/a | # define UF_HIDDEN 0x00008000 |
---|
225 | n/a | #endif |
---|
226 | n/a | |
---|
227 | n/a | #ifndef SF_ARCHIVED |
---|
228 | n/a | # define SF_ARCHIVED 0x00010000 |
---|
229 | n/a | #endif |
---|
230 | n/a | |
---|
231 | n/a | #ifndef SF_IMMUTABLE |
---|
232 | n/a | # define SF_IMMUTABLE 0x00020000 |
---|
233 | n/a | #endif |
---|
234 | n/a | |
---|
235 | n/a | #ifndef SF_APPEND |
---|
236 | n/a | # define SF_APPEND 0x00040000 |
---|
237 | n/a | #endif |
---|
238 | n/a | |
---|
239 | n/a | #ifndef SF_NOUNLINK |
---|
240 | n/a | # define SF_NOUNLINK 0x00100000 |
---|
241 | n/a | #endif |
---|
242 | n/a | |
---|
243 | n/a | #ifndef SF_SNAPSHOT |
---|
244 | n/a | # define SF_SNAPSHOT 0x00200000 |
---|
245 | n/a | #endif |
---|
246 | n/a | |
---|
247 | n/a | static mode_t |
---|
248 | n/a | _PyLong_AsMode_t(PyObject *op) |
---|
249 | n/a | { |
---|
250 | n/a | unsigned long value; |
---|
251 | n/a | mode_t mode; |
---|
252 | n/a | |
---|
253 | n/a | value = PyLong_AsUnsignedLong(op); |
---|
254 | n/a | if ((value == (unsigned long)-1) && PyErr_Occurred()) |
---|
255 | n/a | return (mode_t)-1; |
---|
256 | n/a | |
---|
257 | n/a | mode = (mode_t)value; |
---|
258 | n/a | if ((unsigned long)mode != value) { |
---|
259 | n/a | PyErr_SetString(PyExc_OverflowError, "mode out of range"); |
---|
260 | n/a | return (mode_t)-1; |
---|
261 | n/a | } |
---|
262 | n/a | return mode; |
---|
263 | n/a | } |
---|
264 | n/a | |
---|
265 | n/a | |
---|
266 | n/a | #define stat_S_ISFUNC(isfunc, doc) \ |
---|
267 | n/a | static PyObject * \ |
---|
268 | n/a | stat_ ##isfunc (PyObject *self, PyObject *omode) \ |
---|
269 | n/a | { \ |
---|
270 | n/a | mode_t mode = _PyLong_AsMode_t(omode); \ |
---|
271 | n/a | if ((mode == (mode_t)-1) && PyErr_Occurred()) \ |
---|
272 | n/a | return NULL; \ |
---|
273 | n/a | return PyBool_FromLong(isfunc(mode)); \ |
---|
274 | n/a | } \ |
---|
275 | n/a | PyDoc_STRVAR(stat_ ## isfunc ## _doc, doc) |
---|
276 | n/a | |
---|
277 | n/a | stat_S_ISFUNC(S_ISDIR, |
---|
278 | n/a | "S_ISDIR(mode) -> bool\n\n" |
---|
279 | n/a | "Return True if mode is from a directory."); |
---|
280 | n/a | |
---|
281 | n/a | stat_S_ISFUNC(S_ISCHR, |
---|
282 | n/a | "S_ISCHR(mode) -> bool\n\n" |
---|
283 | n/a | "Return True if mode is from a character special device file."); |
---|
284 | n/a | |
---|
285 | n/a | stat_S_ISFUNC(S_ISBLK, |
---|
286 | n/a | "S_ISBLK(mode) -> bool\n\n" |
---|
287 | n/a | "Return True if mode is from a block special device file."); |
---|
288 | n/a | |
---|
289 | n/a | stat_S_ISFUNC(S_ISREG, |
---|
290 | n/a | "S_ISREG(mode) -> bool\n\n" |
---|
291 | n/a | "Return True if mode is from a regular file."); |
---|
292 | n/a | |
---|
293 | n/a | stat_S_ISFUNC(S_ISFIFO, |
---|
294 | n/a | "S_ISFIFO(mode) -> bool\n\n" |
---|
295 | n/a | "Return True if mode is from a FIFO (named pipe)."); |
---|
296 | n/a | |
---|
297 | n/a | stat_S_ISFUNC(S_ISLNK, |
---|
298 | n/a | "S_ISLNK(mode) -> bool\n\n" |
---|
299 | n/a | "Return True if mode is from a symbolic link."); |
---|
300 | n/a | |
---|
301 | n/a | stat_S_ISFUNC(S_ISSOCK, |
---|
302 | n/a | "S_ISSOCK(mode) -> bool\n\n" |
---|
303 | n/a | "Return True if mode is from a socket."); |
---|
304 | n/a | |
---|
305 | n/a | stat_S_ISFUNC(S_ISDOOR, |
---|
306 | n/a | "S_ISDOOR(mode) -> bool\n\n" |
---|
307 | n/a | "Return True if mode is from a door."); |
---|
308 | n/a | |
---|
309 | n/a | stat_S_ISFUNC(S_ISPORT, |
---|
310 | n/a | "S_ISPORT(mode) -> bool\n\n" |
---|
311 | n/a | "Return True if mode is from an event port."); |
---|
312 | n/a | |
---|
313 | n/a | stat_S_ISFUNC(S_ISWHT, |
---|
314 | n/a | "S_ISWHT(mode) -> bool\n\n" |
---|
315 | n/a | "Return True if mode is from a whiteout."); |
---|
316 | n/a | |
---|
317 | n/a | |
---|
318 | n/a | PyDoc_STRVAR(stat_S_IMODE_doc, |
---|
319 | n/a | "Return the portion of the file's mode that can be set by os.chmod()."); |
---|
320 | n/a | |
---|
321 | n/a | static PyObject * |
---|
322 | n/a | stat_S_IMODE(PyObject *self, PyObject *omode) |
---|
323 | n/a | { |
---|
324 | n/a | mode_t mode = _PyLong_AsMode_t(omode); |
---|
325 | n/a | if ((mode == (mode_t)-1) && PyErr_Occurred()) |
---|
326 | n/a | return NULL; |
---|
327 | n/a | return PyLong_FromUnsignedLong(mode & S_IMODE); |
---|
328 | n/a | } |
---|
329 | n/a | |
---|
330 | n/a | |
---|
331 | n/a | PyDoc_STRVAR(stat_S_IFMT_doc, |
---|
332 | n/a | "Return the portion of the file's mode that describes the file type."); |
---|
333 | n/a | |
---|
334 | n/a | static PyObject * |
---|
335 | n/a | stat_S_IFMT(PyObject *self, PyObject *omode) |
---|
336 | n/a | { |
---|
337 | n/a | mode_t mode = _PyLong_AsMode_t(omode); |
---|
338 | n/a | if ((mode == (mode_t)-1) && PyErr_Occurred()) |
---|
339 | n/a | return NULL; |
---|
340 | n/a | return PyLong_FromUnsignedLong(mode & S_IFMT); |
---|
341 | n/a | } |
---|
342 | n/a | |
---|
343 | n/a | /* file type chars according to |
---|
344 | n/a | http://en.wikibooks.org/wiki/C_Programming/POSIX_Reference/sys/stat.h */ |
---|
345 | n/a | |
---|
346 | n/a | static char |
---|
347 | n/a | filetype(mode_t mode) |
---|
348 | n/a | { |
---|
349 | n/a | /* common cases first */ |
---|
350 | n/a | if (S_ISREG(mode)) return '-'; |
---|
351 | n/a | if (S_ISDIR(mode)) return 'd'; |
---|
352 | n/a | if (S_ISLNK(mode)) return 'l'; |
---|
353 | n/a | /* special files */ |
---|
354 | n/a | if (S_ISBLK(mode)) return 'b'; |
---|
355 | n/a | if (S_ISCHR(mode)) return 'c'; |
---|
356 | n/a | if (S_ISFIFO(mode)) return 'p'; |
---|
357 | n/a | if (S_ISSOCK(mode)) return 's'; |
---|
358 | n/a | /* non-standard types */ |
---|
359 | n/a | if (S_ISDOOR(mode)) return 'D'; |
---|
360 | n/a | if (S_ISPORT(mode)) return 'P'; |
---|
361 | n/a | if (S_ISWHT(mode)) return 'w'; |
---|
362 | n/a | /* unknown */ |
---|
363 | n/a | return '?'; |
---|
364 | n/a | } |
---|
365 | n/a | |
---|
366 | n/a | static void |
---|
367 | n/a | fileperm(mode_t mode, char *buf) |
---|
368 | n/a | { |
---|
369 | n/a | buf[0] = mode & S_IRUSR ? 'r' : '-'; |
---|
370 | n/a | buf[1] = mode & S_IWUSR ? 'w' : '-'; |
---|
371 | n/a | if (mode & S_ISUID) { |
---|
372 | n/a | buf[2] = mode & S_IXUSR ? 's' : 'S'; |
---|
373 | n/a | } else { |
---|
374 | n/a | buf[2] = mode & S_IXUSR ? 'x' : '-'; |
---|
375 | n/a | } |
---|
376 | n/a | buf[3] = mode & S_IRGRP ? 'r' : '-'; |
---|
377 | n/a | buf[4] = mode & S_IWGRP ? 'w' : '-'; |
---|
378 | n/a | if (mode & S_ISGID) { |
---|
379 | n/a | buf[5] = mode & S_IXGRP ? 's' : 'S'; |
---|
380 | n/a | } else { |
---|
381 | n/a | buf[5] = mode & S_IXGRP ? 'x' : '-'; |
---|
382 | n/a | } |
---|
383 | n/a | buf[6] = mode & S_IROTH ? 'r' : '-'; |
---|
384 | n/a | buf[7] = mode & S_IWOTH ? 'w' : '-'; |
---|
385 | n/a | if (mode & S_ISVTX) { |
---|
386 | n/a | buf[8] = mode & S_IXOTH ? 't' : 'T'; |
---|
387 | n/a | } else { |
---|
388 | n/a | buf[8] = mode & S_IXOTH ? 'x' : '-'; |
---|
389 | n/a | } |
---|
390 | n/a | } |
---|
391 | n/a | |
---|
392 | n/a | PyDoc_STRVAR(stat_filemode_doc, |
---|
393 | n/a | "Convert a file's mode to a string of the form '-rwxrwxrwx'"); |
---|
394 | n/a | |
---|
395 | n/a | static PyObject * |
---|
396 | n/a | stat_filemode(PyObject *self, PyObject *omode) |
---|
397 | n/a | { |
---|
398 | n/a | char buf[10]; |
---|
399 | n/a | mode_t mode; |
---|
400 | n/a | |
---|
401 | n/a | mode = _PyLong_AsMode_t(omode); |
---|
402 | n/a | if ((mode == (mode_t)-1) && PyErr_Occurred()) |
---|
403 | n/a | return NULL; |
---|
404 | n/a | |
---|
405 | n/a | buf[0] = filetype(mode); |
---|
406 | n/a | fileperm(mode, &buf[1]); |
---|
407 | n/a | return PyUnicode_FromStringAndSize(buf, 10); |
---|
408 | n/a | } |
---|
409 | n/a | |
---|
410 | n/a | |
---|
411 | n/a | static PyMethodDef stat_methods[] = { |
---|
412 | n/a | {"S_ISDIR", stat_S_ISDIR, METH_O, stat_S_ISDIR_doc}, |
---|
413 | n/a | {"S_ISCHR", stat_S_ISCHR, METH_O, stat_S_ISCHR_doc}, |
---|
414 | n/a | {"S_ISBLK", stat_S_ISBLK, METH_O, stat_S_ISBLK_doc}, |
---|
415 | n/a | {"S_ISREG", stat_S_ISREG, METH_O, stat_S_ISREG_doc}, |
---|
416 | n/a | {"S_ISFIFO", stat_S_ISFIFO, METH_O, stat_S_ISFIFO_doc}, |
---|
417 | n/a | {"S_ISLNK", stat_S_ISLNK, METH_O, stat_S_ISLNK_doc}, |
---|
418 | n/a | {"S_ISSOCK", stat_S_ISSOCK, METH_O, stat_S_ISSOCK_doc}, |
---|
419 | n/a | {"S_ISDOOR", stat_S_ISDOOR, METH_O, stat_S_ISDOOR_doc}, |
---|
420 | n/a | {"S_ISPORT", stat_S_ISPORT, METH_O, stat_S_ISPORT_doc}, |
---|
421 | n/a | {"S_ISWHT", stat_S_ISWHT, METH_O, stat_S_ISWHT_doc}, |
---|
422 | n/a | {"S_IMODE", stat_S_IMODE, METH_O, stat_S_IMODE_doc}, |
---|
423 | n/a | {"S_IFMT", stat_S_IFMT, METH_O, stat_S_IFMT_doc}, |
---|
424 | n/a | {"filemode", stat_filemode, METH_O, stat_filemode_doc}, |
---|
425 | n/a | {NULL, NULL} /* sentinel */ |
---|
426 | n/a | }; |
---|
427 | n/a | |
---|
428 | n/a | |
---|
429 | n/a | PyDoc_STRVAR(module_doc, |
---|
430 | n/a | "S_IFMT_: file type bits\n\ |
---|
431 | n/a | S_IFDIR: directory\n\ |
---|
432 | n/a | S_IFCHR: character device\n\ |
---|
433 | n/a | S_IFBLK: block device\n\ |
---|
434 | n/a | S_IFREG: regular file\n\ |
---|
435 | n/a | S_IFIFO: fifo (named pipe)\n\ |
---|
436 | n/a | S_IFLNK: symbolic link\n\ |
---|
437 | n/a | S_IFSOCK: socket file\n\ |
---|
438 | n/a | S_IFDOOR: door\n\ |
---|
439 | n/a | S_IFPORT: event port\n\ |
---|
440 | n/a | S_IFWHT: whiteout\n\ |
---|
441 | n/a | \n" |
---|
442 | n/a | |
---|
443 | n/a | "S_ISUID: set UID bit\n\ |
---|
444 | n/a | S_ISGID: set GID bit\n\ |
---|
445 | n/a | S_ENFMT: file locking enforcement\n\ |
---|
446 | n/a | S_ISVTX: sticky bit\n\ |
---|
447 | n/a | S_IREAD: Unix V7 synonym for S_IRUSR\n\ |
---|
448 | n/a | S_IWRITE: Unix V7 synonym for S_IWUSR\n\ |
---|
449 | n/a | S_IEXEC: Unix V7 synonym for S_IXUSR\n\ |
---|
450 | n/a | S_IRWXU: mask for owner permissions\n\ |
---|
451 | n/a | S_IRUSR: read by owner\n\ |
---|
452 | n/a | S_IWUSR: write by owner\n\ |
---|
453 | n/a | S_IXUSR: execute by owner\n\ |
---|
454 | n/a | S_IRWXG: mask for group permissions\n\ |
---|
455 | n/a | S_IRGRP: read by group\n\ |
---|
456 | n/a | S_IWGRP: write by group\n\ |
---|
457 | n/a | S_IXGRP: execute by group\n\ |
---|
458 | n/a | S_IRWXO: mask for others (not in group) permissions\n\ |
---|
459 | n/a | S_IROTH: read by others\n\ |
---|
460 | n/a | S_IWOTH: write by others\n\ |
---|
461 | n/a | S_IXOTH: execute by others\n\ |
---|
462 | n/a | \n" |
---|
463 | n/a | |
---|
464 | n/a | "UF_NODUMP: do not dump file\n\ |
---|
465 | n/a | UF_IMMUTABLE: file may not be changed\n\ |
---|
466 | n/a | UF_APPEND: file may only be appended to\n\ |
---|
467 | n/a | UF_OPAQUE: directory is opaque when viewed through a union stack\n\ |
---|
468 | n/a | UF_NOUNLINK: file may not be renamed or deleted\n\ |
---|
469 | n/a | UF_COMPRESSED: OS X: file is hfs-compressed\n\ |
---|
470 | n/a | UF_HIDDEN: OS X: file should not be displayed\n\ |
---|
471 | n/a | SF_ARCHIVED: file may be archived\n\ |
---|
472 | n/a | SF_IMMUTABLE: file may not be changed\n\ |
---|
473 | n/a | SF_APPEND: file may only be appended to\n\ |
---|
474 | n/a | SF_NOUNLINK: file may not be renamed or deleted\n\ |
---|
475 | n/a | SF_SNAPSHOT: file is a snapshot file\n\ |
---|
476 | n/a | \n" |
---|
477 | n/a | |
---|
478 | n/a | "ST_MODE\n\ |
---|
479 | n/a | ST_INO\n\ |
---|
480 | n/a | ST_DEV\n\ |
---|
481 | n/a | ST_NLINK\n\ |
---|
482 | n/a | ST_UID\n\ |
---|
483 | n/a | ST_GID\n\ |
---|
484 | n/a | ST_SIZE\n\ |
---|
485 | n/a | ST_ATIME\n\ |
---|
486 | n/a | ST_MTIME\n\ |
---|
487 | n/a | ST_CTIME\n\ |
---|
488 | n/a | \n" |
---|
489 | n/a | |
---|
490 | n/a | "FILE_ATTRIBUTE_*: Windows file attribute constants\n\ |
---|
491 | n/a | (only present on Windows)\n\ |
---|
492 | n/a | "); |
---|
493 | n/a | |
---|
494 | n/a | |
---|
495 | n/a | static struct PyModuleDef statmodule = { |
---|
496 | n/a | PyModuleDef_HEAD_INIT, |
---|
497 | n/a | "_stat", |
---|
498 | n/a | module_doc, |
---|
499 | n/a | -1, |
---|
500 | n/a | stat_methods, |
---|
501 | n/a | NULL, |
---|
502 | n/a | NULL, |
---|
503 | n/a | NULL, |
---|
504 | n/a | NULL |
---|
505 | n/a | }; |
---|
506 | n/a | |
---|
507 | n/a | PyMODINIT_FUNC |
---|
508 | n/a | PyInit__stat(void) |
---|
509 | n/a | { |
---|
510 | n/a | PyObject *m; |
---|
511 | n/a | m = PyModule_Create(&statmodule); |
---|
512 | n/a | if (m == NULL) |
---|
513 | n/a | return NULL; |
---|
514 | n/a | |
---|
515 | n/a | if (PyModule_AddIntMacro(m, S_IFDIR)) return NULL; |
---|
516 | n/a | if (PyModule_AddIntMacro(m, S_IFCHR)) return NULL; |
---|
517 | n/a | if (PyModule_AddIntMacro(m, S_IFBLK)) return NULL; |
---|
518 | n/a | if (PyModule_AddIntMacro(m, S_IFREG)) return NULL; |
---|
519 | n/a | if (PyModule_AddIntMacro(m, S_IFIFO)) return NULL; |
---|
520 | n/a | if (PyModule_AddIntMacro(m, S_IFLNK)) return NULL; |
---|
521 | n/a | if (PyModule_AddIntMacro(m, S_IFSOCK)) return NULL; |
---|
522 | n/a | if (PyModule_AddIntMacro(m, S_IFDOOR)) return NULL; |
---|
523 | n/a | if (PyModule_AddIntMacro(m, S_IFPORT)) return NULL; |
---|
524 | n/a | if (PyModule_AddIntMacro(m, S_IFWHT)) return NULL; |
---|
525 | n/a | |
---|
526 | n/a | if (PyModule_AddIntMacro(m, S_ISUID)) return NULL; |
---|
527 | n/a | if (PyModule_AddIntMacro(m, S_ISGID)) return NULL; |
---|
528 | n/a | if (PyModule_AddIntMacro(m, S_ISVTX)) return NULL; |
---|
529 | n/a | if (PyModule_AddIntMacro(m, S_ENFMT)) return NULL; |
---|
530 | n/a | |
---|
531 | n/a | if (PyModule_AddIntMacro(m, S_IREAD)) return NULL; |
---|
532 | n/a | if (PyModule_AddIntMacro(m, S_IWRITE)) return NULL; |
---|
533 | n/a | if (PyModule_AddIntMacro(m, S_IEXEC)) return NULL; |
---|
534 | n/a | |
---|
535 | n/a | if (PyModule_AddIntMacro(m, S_IRWXU)) return NULL; |
---|
536 | n/a | if (PyModule_AddIntMacro(m, S_IRUSR)) return NULL; |
---|
537 | n/a | if (PyModule_AddIntMacro(m, S_IWUSR)) return NULL; |
---|
538 | n/a | if (PyModule_AddIntMacro(m, S_IXUSR)) return NULL; |
---|
539 | n/a | |
---|
540 | n/a | if (PyModule_AddIntMacro(m, S_IRWXG)) return NULL; |
---|
541 | n/a | if (PyModule_AddIntMacro(m, S_IRGRP)) return NULL; |
---|
542 | n/a | if (PyModule_AddIntMacro(m, S_IWGRP)) return NULL; |
---|
543 | n/a | if (PyModule_AddIntMacro(m, S_IXGRP)) return NULL; |
---|
544 | n/a | |
---|
545 | n/a | if (PyModule_AddIntMacro(m, S_IRWXO)) return NULL; |
---|
546 | n/a | if (PyModule_AddIntMacro(m, S_IROTH)) return NULL; |
---|
547 | n/a | if (PyModule_AddIntMacro(m, S_IWOTH)) return NULL; |
---|
548 | n/a | if (PyModule_AddIntMacro(m, S_IXOTH)) return NULL; |
---|
549 | n/a | |
---|
550 | n/a | if (PyModule_AddIntMacro(m, UF_NODUMP)) return NULL; |
---|
551 | n/a | if (PyModule_AddIntMacro(m, UF_IMMUTABLE)) return NULL; |
---|
552 | n/a | if (PyModule_AddIntMacro(m, UF_APPEND)) return NULL; |
---|
553 | n/a | if (PyModule_AddIntMacro(m, UF_OPAQUE)) return NULL; |
---|
554 | n/a | if (PyModule_AddIntMacro(m, UF_NOUNLINK)) return NULL; |
---|
555 | n/a | if (PyModule_AddIntMacro(m, UF_COMPRESSED)) return NULL; |
---|
556 | n/a | if (PyModule_AddIntMacro(m, UF_HIDDEN)) return NULL; |
---|
557 | n/a | if (PyModule_AddIntMacro(m, SF_ARCHIVED)) return NULL; |
---|
558 | n/a | if (PyModule_AddIntMacro(m, SF_IMMUTABLE)) return NULL; |
---|
559 | n/a | if (PyModule_AddIntMacro(m, SF_APPEND)) return NULL; |
---|
560 | n/a | if (PyModule_AddIntMacro(m, SF_NOUNLINK)) return NULL; |
---|
561 | n/a | if (PyModule_AddIntMacro(m, SF_SNAPSHOT)) return NULL; |
---|
562 | n/a | |
---|
563 | n/a | if (PyModule_AddIntConstant(m, "ST_MODE", 0)) return NULL; |
---|
564 | n/a | if (PyModule_AddIntConstant(m, "ST_INO", 1)) return NULL; |
---|
565 | n/a | if (PyModule_AddIntConstant(m, "ST_DEV", 2)) return NULL; |
---|
566 | n/a | if (PyModule_AddIntConstant(m, "ST_NLINK", 3)) return NULL; |
---|
567 | n/a | if (PyModule_AddIntConstant(m, "ST_UID", 4)) return NULL; |
---|
568 | n/a | if (PyModule_AddIntConstant(m, "ST_GID", 5)) return NULL; |
---|
569 | n/a | if (PyModule_AddIntConstant(m, "ST_SIZE", 6)) return NULL; |
---|
570 | n/a | if (PyModule_AddIntConstant(m, "ST_ATIME", 7)) return NULL; |
---|
571 | n/a | if (PyModule_AddIntConstant(m, "ST_MTIME", 8)) return NULL; |
---|
572 | n/a | if (PyModule_AddIntConstant(m, "ST_CTIME", 9)) return NULL; |
---|
573 | n/a | |
---|
574 | n/a | #ifdef MS_WINDOWS |
---|
575 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_ARCHIVE)) return NULL; |
---|
576 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_COMPRESSED)) return NULL; |
---|
577 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_DEVICE)) return NULL; |
---|
578 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_DIRECTORY)) return NULL; |
---|
579 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_ENCRYPTED)) return NULL; |
---|
580 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_HIDDEN)) return NULL; |
---|
581 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_INTEGRITY_STREAM)) return NULL; |
---|
582 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_NORMAL)) return NULL; |
---|
583 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)) return NULL; |
---|
584 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_NO_SCRUB_DATA)) return NULL; |
---|
585 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_OFFLINE)) return NULL; |
---|
586 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_READONLY)) return NULL; |
---|
587 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_REPARSE_POINT)) return NULL; |
---|
588 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_SPARSE_FILE)) return NULL; |
---|
589 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_SYSTEM)) return NULL; |
---|
590 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_TEMPORARY)) return NULL; |
---|
591 | n/a | if (PyModule_AddIntMacro(m, FILE_ATTRIBUTE_VIRTUAL)) return NULL; |
---|
592 | n/a | #endif |
---|
593 | n/a | |
---|
594 | n/a | return m; |
---|
595 | n/a | } |
---|
596 | n/a | |
---|
597 | n/a | #ifdef __cplusplus |
---|
598 | n/a | } |
---|
599 | n/a | #endif |
---|