_stat.c 15 KB

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