fileutils.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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(char*) _Py_EncodeLocaleRaw(
  31. const wchar_t *text,
  32. size_t *error_pos);
  33. PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
  34. #if defined(MS_WINDOWS) || defined(__APPLE__)
  35. /* On Windows, the count parameter of read() is an int (bpo-9015, bpo-9611).
  36. On macOS 10.13, read() and write() with more than INT_MAX bytes
  37. fail with EINVAL (bpo-24658). */
  38. # define _PY_READ_MAX INT_MAX
  39. # define _PY_WRITE_MAX INT_MAX
  40. #else
  41. /* write() should truncate the input to PY_SSIZE_T_MAX bytes,
  42. but it's safer to do it ourself to have a portable behaviour */
  43. # define _PY_READ_MAX PY_SSIZE_T_MAX
  44. # define _PY_WRITE_MAX PY_SSIZE_T_MAX
  45. #endif
  46. #ifdef MS_WINDOWS
  47. struct _Py_stat_struct {
  48. unsigned long st_dev;
  49. uint64_t st_ino;
  50. unsigned short st_mode;
  51. int st_nlink;
  52. int st_uid;
  53. int st_gid;
  54. unsigned long st_rdev;
  55. __int64 st_size;
  56. time_t st_atime;
  57. int st_atime_nsec;
  58. time_t st_mtime;
  59. int st_mtime_nsec;
  60. time_t st_ctime;
  61. int st_ctime_nsec;
  62. unsigned long st_file_attributes;
  63. unsigned long st_reparse_tag;
  64. };
  65. #else
  66. # define _Py_stat_struct stat
  67. #endif
  68. PyAPI_FUNC(int) _Py_fstat(
  69. int fd,
  70. struct _Py_stat_struct *status);
  71. PyAPI_FUNC(int) _Py_fstat_noraise(
  72. int fd,
  73. struct _Py_stat_struct *status);
  74. PyAPI_FUNC(int) _Py_stat(
  75. PyObject *path,
  76. struct stat *status);
  77. PyAPI_FUNC(int) _Py_open(
  78. const char *pathname,
  79. int flags);
  80. PyAPI_FUNC(int) _Py_open_noraise(
  81. const char *pathname,
  82. int flags);
  83. PyAPI_FUNC(FILE *) _Py_wfopen(
  84. const wchar_t *path,
  85. const wchar_t *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. PyAPI_FUNC(int) _Py_isabs(const wchar_t *path);
  118. PyAPI_FUNC(int) _Py_issep(const wchar_t ch);
  119. PyAPI_FUNC(int) _Py_abspath(const wchar_t *path, wchar_t **abspath_p);
  120. PyAPI_FUNC(wchar_t*) _Py_wgetcwd(
  121. wchar_t *buf,
  122. /* Number of characters of 'buf' buffer
  123. including the trailing NUL character */
  124. size_t buflen);
  125. PyAPI_FUNC(int) _Py_get_inheritable(int fd);
  126. PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,
  127. int *atomic_flag_works);
  128. PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable,
  129. int *atomic_flag_works);
  130. PyAPI_FUNC(int) _Py_dup(int fd);
  131. #ifndef MS_WINDOWS
  132. PyAPI_FUNC(int) _Py_get_blocking(int fd);
  133. PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
  134. #else /* MS_WINDOWS */
  135. PyAPI_FUNC(void*) _Py_get_osfhandle_noraise(int fd);
  136. PyAPI_FUNC(void*) _Py_get_osfhandle(int fd);
  137. PyAPI_FUNC(int) _Py_open_osfhandle_noraise(void *handle, int flags);
  138. PyAPI_FUNC(int) _Py_open_osfhandle(void *handle, int flags);
  139. #endif /* MS_WINDOWS */