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