blob: 232d9664cdd013db1350c3b196ff48f5d98b4547 [file] [log] [blame]
Victor Stinner4e314432010-10-07 21:45:39 +00001#ifndef Py_FILEUTILS_H
2#define Py_FILEUTILS_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
Victor Stinner3d4226a2018-08-29 22:21:32 +02008
9#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03080000
10typedef enum {
11 _Py_ERROR_UNKNOWN=0,
12 _Py_ERROR_STRICT,
13 _Py_ERROR_SURROGATEESCAPE,
14 _Py_ERROR_REPLACE,
15 _Py_ERROR_IGNORE,
16 _Py_ERROR_BACKSLASHREPLACE,
17 _Py_ERROR_SURROGATEPASS,
18 _Py_ERROR_XMLCHARREFREPLACE,
19 _Py_ERROR_OTHER
20} _Py_error_handler;
21
22PyAPI_FUNC(_Py_error_handler) _Py_GetErrorHandler(const char *errors);
23#endif
24
25
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +020026#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
Victor Stinnerf6a271a2014-08-01 12:28:48 +020027PyAPI_FUNC(wchar_t *) Py_DecodeLocale(
Victor Stinner168e1172010-10-16 23:16:16 +000028 const char *arg,
29 size_t *size);
Victor Stinner4e314432010-10-07 21:45:39 +000030
Victor Stinnerf6a271a2014-08-01 12:28:48 +020031PyAPI_FUNC(char*) Py_EncodeLocale(
Victor Stinner2f02a512010-11-08 22:43:46 +000032 const wchar_t *text,
33 size_t *error_pos);
Victor Stinner9dd76202017-12-21 16:20:32 +010034
35PyAPI_FUNC(char*) _Py_EncodeLocaleRaw(
36 const wchar_t *text,
37 size_t *error_pos);
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +020038#endif
Victor Stinner4e314432010-10-07 21:45:39 +000039
Victor Stinner9bee3292017-12-21 16:49:13 +010040#ifdef Py_BUILD_CORE
Victor Stinner7ed7aea2018-01-15 10:45:49 +010041PyAPI_FUNC(int) _Py_DecodeUTF8Ex(
Victor Stinner2cba6b82018-01-10 22:46:15 +010042 const char *arg,
Victor Stinner7ed7aea2018-01-15 10:45:49 +010043 Py_ssize_t arglen,
44 wchar_t **wstr,
45 size_t *wlen,
46 const char **reason,
Victor Stinner3d4226a2018-08-29 22:21:32 +020047 _Py_error_handler errors);
Victor Stinner2cba6b82018-01-10 22:46:15 +010048
Victor Stinner7ed7aea2018-01-15 10:45:49 +010049PyAPI_FUNC(int) _Py_EncodeUTF8Ex(
Victor Stinner2cba6b82018-01-10 22:46:15 +010050 const wchar_t *text,
Victor Stinner7ed7aea2018-01-15 10:45:49 +010051 char **str,
52 size_t *error_pos,
53 const char **reason,
54 int raw_malloc,
Victor Stinner3d4226a2018-08-29 22:21:32 +020055 _Py_error_handler errors);
Victor Stinner7ed7aea2018-01-15 10:45:49 +010056
57PyAPI_FUNC(wchar_t*) _Py_DecodeUTF8_surrogateescape(
58 const char *arg,
59 Py_ssize_t arglen);
Victor Stinner3d4226a2018-08-29 22:21:32 +020060#endif
Victor Stinner7ed7aea2018-01-15 10:45:49 +010061
Victor Stinner3d4226a2018-08-29 22:21:32 +020062
63#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03080000
Victor Stinner7ed7aea2018-01-15 10:45:49 +010064PyAPI_FUNC(int) _Py_DecodeLocaleEx(
65 const char *arg,
66 wchar_t **wstr,
67 size_t *wlen,
68 const char **reason,
69 int current_locale,
Victor Stinner3d4226a2018-08-29 22:21:32 +020070 _Py_error_handler errors);
Victor Stinner7ed7aea2018-01-15 10:45:49 +010071
72PyAPI_FUNC(int) _Py_EncodeLocaleEx(
73 const wchar_t *text,
74 char **str,
75 size_t *error_pos,
76 const char **reason,
77 int current_locale,
Victor Stinner3d4226a2018-08-29 22:21:32 +020078 _Py_error_handler errors);
Victor Stinner9bee3292017-12-21 16:49:13 +010079#endif
80
Serhiy Storchaka12ebbc72015-02-22 19:39:36 +020081#ifndef Py_LIMITED_API
Serhiy Storchaka9fab79b2016-09-11 11:03:14 +030082PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
83
Stéphane Wirtel74a8b6e2018-10-18 01:05:04 +020084#if defined(MS_WINDOWS) || defined(__APPLE__)
85 /* On Windows, the count parameter of read() is an int (bpo-9015, bpo-9611).
86 On macOS 10.13, read() and write() with more than INT_MAX bytes
87 fail with EINVAL (bpo-24658). */
88# define _PY_READ_MAX INT_MAX
89# define _PY_WRITE_MAX INT_MAX
90#else
91 /* write() should truncate the input to PY_SSIZE_T_MAX bytes,
92 but it's safer to do it ourself to have a portable behaviour */
93# define _PY_READ_MAX PY_SSIZE_T_MAX
94# define _PY_WRITE_MAX PY_SSIZE_T_MAX
95#endif
96
Steve Dowerf2f373f2015-02-21 08:44:05 -080097#ifdef MS_WINDOWS
98struct _Py_stat_struct {
99 unsigned long st_dev;
Victor Stinner0f6d7332017-03-09 17:34:28 +0100100 uint64_t st_ino;
Steve Dowerf2f373f2015-02-21 08:44:05 -0800101 unsigned short st_mode;
102 int st_nlink;
103 int st_uid;
104 int st_gid;
105 unsigned long st_rdev;
106 __int64 st_size;
107 time_t st_atime;
108 int st_atime_nsec;
109 time_t st_mtime;
110 int st_mtime_nsec;
111 time_t st_ctime;
112 int st_ctime_nsec;
113 unsigned long st_file_attributes;
114};
115#else
116# define _Py_stat_struct stat
117#endif
118
119PyAPI_FUNC(int) _Py_fstat(
120 int fd,
Victor Stinnere134a7f2015-03-30 10:09:31 +0200121 struct _Py_stat_struct *status);
122
123PyAPI_FUNC(int) _Py_fstat_noraise(
124 int fd,
125 struct _Py_stat_struct *status);
Steve Dowerf2f373f2015-02-21 08:44:05 -0800126
Victor Stinner4e314432010-10-07 21:45:39 +0000127PyAPI_FUNC(int) _Py_stat(
Victor Stinnera4a75952010-10-07 22:23:10 +0000128 PyObject *path,
Victor Stinnere134a7f2015-03-30 10:09:31 +0200129 struct stat *status);
Victor Stinner4e314432010-10-07 21:45:39 +0000130
Victor Stinnerdaf45552013-08-28 00:53:59 +0200131PyAPI_FUNC(int) _Py_open(
132 const char *pathname,
133 int flags);
Victor Stinnera555cfc2015-03-18 00:22:14 +0100134
135PyAPI_FUNC(int) _Py_open_noraise(
136 const char *pathname,
137 int flags);
Victor Stinnerdaf45552013-08-28 00:53:59 +0200138
Victor Stinner4e314432010-10-07 21:45:39 +0000139PyAPI_FUNC(FILE *) _Py_wfopen(
140 const wchar_t *path,
141 const wchar_t *mode);
142
143PyAPI_FUNC(FILE*) _Py_fopen(
Victor Stinnerdaf45552013-08-28 00:53:59 +0200144 const char *pathname,
145 const char *mode);
146
147PyAPI_FUNC(FILE*) _Py_fopen_obj(
Victor Stinnera4a75952010-10-07 22:23:10 +0000148 PyObject *path,
Victor Stinner4e314432010-10-07 21:45:39 +0000149 const char *mode);
150
Victor Stinner66aab0c2015-03-19 22:53:20 +0100151PyAPI_FUNC(Py_ssize_t) _Py_read(
152 int fd,
153 void *buf,
154 size_t count);
155
156PyAPI_FUNC(Py_ssize_t) _Py_write(
157 int fd,
158 const void *buf,
159 size_t count);
160
Victor Stinner82c3e452015-04-01 18:34:45 +0200161PyAPI_FUNC(Py_ssize_t) _Py_write_noraise(
162 int fd,
163 const void *buf,
164 size_t count);
165
Victor Stinner4e314432010-10-07 21:45:39 +0000166#ifdef HAVE_READLINK
167PyAPI_FUNC(int) _Py_wreadlink(
168 const wchar_t *path,
169 wchar_t *buf,
170 size_t bufsiz);
171#endif
172
173#ifdef HAVE_REALPATH
174PyAPI_FUNC(wchar_t*) _Py_wrealpath(
175 const wchar_t *path,
Victor Stinner015f4d82010-10-07 22:29:53 +0000176 wchar_t *resolved_path,
177 size_t resolved_path_size);
Victor Stinner4e314432010-10-07 21:45:39 +0000178#endif
179
180PyAPI_FUNC(wchar_t*) _Py_wgetcwd(
181 wchar_t *buf,
182 size_t size);
183
Victor Stinnerdaf45552013-08-28 00:53:59 +0200184PyAPI_FUNC(int) _Py_get_inheritable(int fd);
185
186PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,
187 int *atomic_flag_works);
188
Alexey Izbyshevc1e46e92018-02-06 09:09:34 +0300189PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable,
190 int *atomic_flag_works);
191
Victor Stinnerdaf45552013-08-28 00:53:59 +0200192PyAPI_FUNC(int) _Py_dup(int fd);
Victor Stinner1db9e7b2014-07-29 22:32:47 +0200193
194#ifndef MS_WINDOWS
195PyAPI_FUNC(int) _Py_get_blocking(int fd);
196
197PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
198#endif /* !MS_WINDOWS */
199
Victor Stinnercb064fc2018-01-15 15:58:02 +0100200PyAPI_FUNC(int) _Py_GetLocaleconvNumeric(
201 PyObject **decimal_point,
202 PyObject **thousands_sep,
203 const char **grouping);
204
Victor Stinner1db9e7b2014-07-29 22:32:47 +0200205#endif /* Py_LIMITED_API */
Victor Stinnerdaf45552013-08-28 00:53:59 +0200206
Victor Stinnerd500e532018-08-28 17:27:36 +0200207
208#ifdef Py_BUILD_CORE
209PyAPI_FUNC(int) _Py_GetForceASCII(void);
210#endif
211
Victor Stinner4e314432010-10-07 21:45:39 +0000212#ifdef __cplusplus
213}
214#endif
215
216#endif /* !Py_FILEUTILS_H */