fileutils.h 4.2 KB

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