fileutils.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. #ifdef Py_BUILD_CORE
  18. PyAPI_FUNC(int) _Py_DecodeUTF8Ex(
  19. const char *arg,
  20. Py_ssize_t arglen,
  21. wchar_t **wstr,
  22. size_t *wlen,
  23. const char **reason,
  24. int surrogateescape);
  25. PyAPI_FUNC(int) _Py_EncodeUTF8Ex(
  26. const wchar_t *text,
  27. char **str,
  28. size_t *error_pos,
  29. const char **reason,
  30. int raw_malloc,
  31. int surrogateescape);
  32. PyAPI_FUNC(wchar_t*) _Py_DecodeUTF8_surrogateescape(
  33. const char *arg,
  34. Py_ssize_t arglen);
  35. PyAPI_FUNC(int) _Py_DecodeLocaleEx(
  36. const char *arg,
  37. wchar_t **wstr,
  38. size_t *wlen,
  39. const char **reason,
  40. int current_locale,
  41. int surrogateescape);
  42. PyAPI_FUNC(int) _Py_EncodeLocaleEx(
  43. const wchar_t *text,
  44. char **str,
  45. size_t *error_pos,
  46. const char **reason,
  47. int current_locale,
  48. int surrogateescape);
  49. #endif
  50. #ifndef Py_LIMITED_API
  51. PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
  52. #if defined(MS_WINDOWS) || defined(__APPLE__)
  53. /* On Windows, the count parameter of read() is an int (bpo-9015, bpo-9611).
  54. On macOS 10.13, read() and write() with more than INT_MAX bytes
  55. fail with EINVAL (bpo-24658). */
  56. # define _PY_READ_MAX INT_MAX
  57. # define _PY_WRITE_MAX INT_MAX
  58. #else
  59. /* write() should truncate the input to PY_SSIZE_T_MAX bytes,
  60. but it's safer to do it ourself to have a portable behaviour */
  61. # define _PY_READ_MAX PY_SSIZE_T_MAX
  62. # define _PY_WRITE_MAX PY_SSIZE_T_MAX
  63. #endif
  64. #ifdef MS_WINDOWS
  65. struct _Py_stat_struct {
  66. unsigned long st_dev;
  67. uint64_t st_ino;
  68. unsigned short st_mode;
  69. int st_nlink;
  70. int st_uid;
  71. int st_gid;
  72. unsigned long st_rdev;
  73. __int64 st_size;
  74. time_t st_atime;
  75. int st_atime_nsec;
  76. time_t st_mtime;
  77. int st_mtime_nsec;
  78. time_t st_ctime;
  79. int st_ctime_nsec;
  80. unsigned long st_file_attributes;
  81. };
  82. #else
  83. # define _Py_stat_struct stat
  84. #endif
  85. PyAPI_FUNC(int) _Py_fstat(
  86. int fd,
  87. struct _Py_stat_struct *status);
  88. PyAPI_FUNC(int) _Py_fstat_noraise(
  89. int fd,
  90. struct _Py_stat_struct *status);
  91. PyAPI_FUNC(int) _Py_stat(
  92. PyObject *path,
  93. struct stat *status);
  94. PyAPI_FUNC(int) _Py_open(
  95. const char *pathname,
  96. int flags);
  97. PyAPI_FUNC(int) _Py_open_noraise(
  98. const char *pathname,
  99. int flags);
  100. PyAPI_FUNC(FILE *) _Py_wfopen(
  101. const wchar_t *path,
  102. const wchar_t *mode);
  103. PyAPI_FUNC(FILE*) _Py_fopen(
  104. const char *pathname,
  105. const char *mode);
  106. PyAPI_FUNC(FILE*) _Py_fopen_obj(
  107. PyObject *path,
  108. const char *mode);
  109. PyAPI_FUNC(Py_ssize_t) _Py_read(
  110. int fd,
  111. void *buf,
  112. size_t count);
  113. PyAPI_FUNC(Py_ssize_t) _Py_write(
  114. int fd,
  115. const void *buf,
  116. size_t count);
  117. PyAPI_FUNC(Py_ssize_t) _Py_write_noraise(
  118. int fd,
  119. const void *buf,
  120. size_t count);
  121. #ifdef HAVE_READLINK
  122. PyAPI_FUNC(int) _Py_wreadlink(
  123. const wchar_t *path,
  124. wchar_t *buf,
  125. size_t bufsiz);
  126. #endif
  127. #ifdef HAVE_REALPATH
  128. PyAPI_FUNC(wchar_t*) _Py_wrealpath(
  129. const wchar_t *path,
  130. wchar_t *resolved_path,
  131. size_t resolved_path_size);
  132. #endif
  133. PyAPI_FUNC(wchar_t*) _Py_wgetcwd(
  134. wchar_t *buf,
  135. size_t size);
  136. PyAPI_FUNC(int) _Py_get_inheritable(int fd);
  137. PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,
  138. int *atomic_flag_works);
  139. PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable,
  140. int *atomic_flag_works);
  141. PyAPI_FUNC(int) _Py_dup(int fd);
  142. #ifndef MS_WINDOWS
  143. PyAPI_FUNC(int) _Py_get_blocking(int fd);
  144. PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
  145. #endif /* !MS_WINDOWS */
  146. PyAPI_FUNC(int) _Py_GetLocaleconvNumeric(
  147. PyObject **decimal_point,
  148. PyObject **thousands_sep,
  149. const char **grouping);
  150. #endif /* Py_LIMITED_API */
  151. #ifdef Py_BUILD_CORE
  152. PyAPI_FUNC(int) _Py_GetForceASCII(void);
  153. /* Reset "force ASCII" mode (if it was initialized).
  154. This function should be called when Python changes the LC_CTYPE locale,
  155. so the "force ASCII" mode can be detected again on the new locale
  156. encoding. */
  157. PyAPI_FUNC(void) _Py_ResetForceASCII(void);
  158. #endif
  159. #ifdef __cplusplus
  160. }
  161. #endif
  162. #endif /* !Py_FILEUTILS_H */