fileutils.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #ifndef Py_CPYTHON_FILEUTILS_H
  2. # error "this header file must not be included directly"
  3. #endif
  4. typedef enum {
  5. _Py_ERROR_UNKNOWN=0,
  6. _Py_ERROR_STRICT,
  7. _Py_ERROR_SURROGATEESCAPE,
  8. _Py_ERROR_REPLACE,
  9. _Py_ERROR_IGNORE,
  10. _Py_ERROR_BACKSLASHREPLACE,
  11. _Py_ERROR_SURROGATEPASS,
  12. _Py_ERROR_XMLCHARREFREPLACE,
  13. _Py_ERROR_OTHER
  14. } _Py_error_handler;
  15. PyAPI_FUNC(_Py_error_handler) _Py_GetErrorHandler(const char *errors);
  16. PyAPI_FUNC(int) _Py_DecodeLocaleEx(
  17. const char *arg,
  18. wchar_t **wstr,
  19. size_t *wlen,
  20. const char **reason,
  21. int current_locale,
  22. _Py_error_handler errors);
  23. PyAPI_FUNC(int) _Py_EncodeLocaleEx(
  24. const wchar_t *text,
  25. char **str,
  26. size_t *error_pos,
  27. const char **reason,
  28. int current_locale,
  29. _Py_error_handler errors);
  30. PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
  31. #if defined(MS_WINDOWS) || defined(__APPLE__)
  32. /* On Windows, the count parameter of read() is an int (bpo-9015, bpo-9611).
  33. On macOS 10.13, read() and write() with more than INT_MAX bytes
  34. fail with EINVAL (bpo-24658). */
  35. # define _PY_READ_MAX INT_MAX
  36. # define _PY_WRITE_MAX INT_MAX
  37. #else
  38. /* write() should truncate the input to PY_SSIZE_T_MAX bytes,
  39. but it's safer to do it ourself to have a portable behaviour */
  40. # define _PY_READ_MAX PY_SSIZE_T_MAX
  41. # define _PY_WRITE_MAX PY_SSIZE_T_MAX
  42. #endif
  43. #ifdef MS_WINDOWS
  44. struct _Py_stat_struct {
  45. unsigned long st_dev;
  46. uint64_t st_ino;
  47. unsigned short st_mode;
  48. int st_nlink;
  49. int st_uid;
  50. int st_gid;
  51. unsigned long st_rdev;
  52. __int64 st_size;
  53. time_t st_atime;
  54. int st_atime_nsec;
  55. time_t st_mtime;
  56. int st_mtime_nsec;
  57. time_t st_ctime;
  58. int st_ctime_nsec;
  59. unsigned long st_file_attributes;
  60. unsigned long st_reparse_tag;
  61. };
  62. #else
  63. # define _Py_stat_struct stat
  64. #endif
  65. PyAPI_FUNC(int) _Py_fstat(
  66. int fd,
  67. struct _Py_stat_struct *status);
  68. PyAPI_FUNC(int) _Py_fstat_noraise(
  69. int fd,
  70. struct _Py_stat_struct *status);
  71. PyAPI_FUNC(int) _Py_stat(
  72. PyObject *path,
  73. struct stat *status);
  74. PyAPI_FUNC(int) _Py_open(
  75. const char *pathname,
  76. int flags);
  77. PyAPI_FUNC(int) _Py_open_noraise(
  78. const char *pathname,
  79. int flags);
  80. PyAPI_FUNC(FILE *) _Py_wfopen(
  81. const wchar_t *path,
  82. const wchar_t *mode);
  83. PyAPI_FUNC(FILE*) _Py_fopen(
  84. const char *pathname,
  85. const char *mode);
  86. PyAPI_FUNC(FILE*) _Py_fopen_obj(
  87. PyObject *path,
  88. const char *mode);
  89. PyAPI_FUNC(Py_ssize_t) _Py_read(
  90. int fd,
  91. void *buf,
  92. size_t count);
  93. PyAPI_FUNC(Py_ssize_t) _Py_write(
  94. int fd,
  95. const void *buf,
  96. size_t count);
  97. PyAPI_FUNC(Py_ssize_t) _Py_write_noraise(
  98. int fd,
  99. const void *buf,
  100. size_t count);
  101. #ifdef HAVE_READLINK
  102. PyAPI_FUNC(int) _Py_wreadlink(
  103. const wchar_t *path,
  104. wchar_t *buf,
  105. /* Number of characters of 'buf' buffer
  106. including the trailing NUL character */
  107. size_t buflen);
  108. #endif
  109. #ifdef HAVE_REALPATH
  110. PyAPI_FUNC(wchar_t*) _Py_wrealpath(
  111. const wchar_t *path,
  112. wchar_t *resolved_path,
  113. /* Number of characters of 'resolved_path' buffer
  114. including the trailing NUL character */
  115. size_t resolved_path_len);
  116. #endif
  117. #ifndef MS_WINDOWS
  118. PyAPI_FUNC(int) _Py_isabs(const wchar_t *path);
  119. #endif
  120. PyAPI_FUNC(int) _Py_abspath(const wchar_t *path, wchar_t **abspath_p);
  121. PyAPI_FUNC(wchar_t*) _Py_wgetcwd(
  122. wchar_t *buf,
  123. /* Number of characters of 'buf' buffer
  124. including the trailing NUL character */
  125. size_t buflen);
  126. PyAPI_FUNC(int) _Py_get_inheritable(int fd);
  127. PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,
  128. int *atomic_flag_works);
  129. PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable,
  130. int *atomic_flag_works);
  131. PyAPI_FUNC(int) _Py_dup(int fd);
  132. #ifndef MS_WINDOWS
  133. PyAPI_FUNC(int) _Py_get_blocking(int fd);
  134. PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
  135. #endif /* !MS_WINDOWS */