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