blob: 830e56ad367a18e7b1e525abf5e176a7c2984d96 [file] [log] [blame]
Victor Stinner4e314432010-10-07 21:45:39 +00001#ifndef Py_FILEUTILS_H
2#define Py_FILEUTILS_H
Victor Stinner4e314432010-10-07 21:45:39 +00003#ifdef __cplusplus
4extern "C" {
5#endif
6
Victor Stinner9fc57a32018-11-07 00:44:03 +01007#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
8PyAPI_FUNC(wchar_t *) Py_DecodeLocale(
9 const char *arg,
10 size_t *size);
11
12PyAPI_FUNC(char*) Py_EncodeLocale(
13 const wchar_t *text,
14 size_t *error_pos);
15
16PyAPI_FUNC(char*) _Py_EncodeLocaleRaw(
17 const wchar_t *text,
18 size_t *error_pos);
19#endif
20
Victor Stinner3d4226a2018-08-29 22:21:32 +020021
22#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03080000
23typedef 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
35PyAPI_FUNC(_Py_error_handler) _Py_GetErrorHandler(const char *errors);
Victor Stinner3d4226a2018-08-29 22:21:32 +020036
Victor Stinner7ed7aea2018-01-15 10:45:49 +010037PyAPI_FUNC(int) _Py_DecodeLocaleEx(
38 const char *arg,
39 wchar_t **wstr,
40 size_t *wlen,
41 const char **reason,
42 int current_locale,
Victor Stinner3d4226a2018-08-29 22:21:32 +020043 _Py_error_handler errors);
Victor Stinner7ed7aea2018-01-15 10:45:49 +010044
45PyAPI_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,
Victor Stinner3d4226a2018-08-29 22:21:32 +020051 _Py_error_handler errors);
Victor Stinner9bee3292017-12-21 16:49:13 +010052#endif
53
Serhiy Storchaka12ebbc72015-02-22 19:39:36 +020054#ifndef Py_LIMITED_API
Serhiy Storchaka9fab79b2016-09-11 11:03:14 +030055PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
56
Stéphane Wirtel74a8b6e2018-10-18 01:05:04 +020057#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
Steve Dowerf2f373f2015-02-21 08:44:05 -080070#ifdef MS_WINDOWS
71struct _Py_stat_struct {
72 unsigned long st_dev;
Victor Stinner0f6d7332017-03-09 17:34:28 +010073 uint64_t st_ino;
Steve Dowerf2f373f2015-02-21 08:44:05 -080074 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};
88#else
89# define _Py_stat_struct stat
90#endif
91
92PyAPI_FUNC(int) _Py_fstat(
93 int fd,
Victor Stinnere134a7f2015-03-30 10:09:31 +020094 struct _Py_stat_struct *status);
95
96PyAPI_FUNC(int) _Py_fstat_noraise(
97 int fd,
98 struct _Py_stat_struct *status);
Steve Dowerf2f373f2015-02-21 08:44:05 -080099
Victor Stinner4e314432010-10-07 21:45:39 +0000100PyAPI_FUNC(int) _Py_stat(
Victor Stinnera4a75952010-10-07 22:23:10 +0000101 PyObject *path,
Victor Stinnere134a7f2015-03-30 10:09:31 +0200102 struct stat *status);
Victor Stinner4e314432010-10-07 21:45:39 +0000103
Victor Stinnerdaf45552013-08-28 00:53:59 +0200104PyAPI_FUNC(int) _Py_open(
105 const char *pathname,
106 int flags);
Victor Stinnera555cfc2015-03-18 00:22:14 +0100107
108PyAPI_FUNC(int) _Py_open_noraise(
109 const char *pathname,
110 int flags);
Victor Stinnerdaf45552013-08-28 00:53:59 +0200111
Victor Stinner4e314432010-10-07 21:45:39 +0000112PyAPI_FUNC(FILE *) _Py_wfopen(
113 const wchar_t *path,
114 const wchar_t *mode);
115
116PyAPI_FUNC(FILE*) _Py_fopen(
Victor Stinnerdaf45552013-08-28 00:53:59 +0200117 const char *pathname,
118 const char *mode);
119
120PyAPI_FUNC(FILE*) _Py_fopen_obj(
Victor Stinnera4a75952010-10-07 22:23:10 +0000121 PyObject *path,
Victor Stinner4e314432010-10-07 21:45:39 +0000122 const char *mode);
123
Victor Stinner66aab0c2015-03-19 22:53:20 +0100124PyAPI_FUNC(Py_ssize_t) _Py_read(
125 int fd,
126 void *buf,
127 size_t count);
128
129PyAPI_FUNC(Py_ssize_t) _Py_write(
130 int fd,
131 const void *buf,
132 size_t count);
133
Victor Stinner82c3e452015-04-01 18:34:45 +0200134PyAPI_FUNC(Py_ssize_t) _Py_write_noraise(
135 int fd,
136 const void *buf,
137 size_t count);
138
Victor Stinner4e314432010-10-07 21:45:39 +0000139#ifdef HAVE_READLINK
140PyAPI_FUNC(int) _Py_wreadlink(
141 const wchar_t *path,
142 wchar_t *buf,
143 size_t bufsiz);
144#endif
145
146#ifdef HAVE_REALPATH
147PyAPI_FUNC(wchar_t*) _Py_wrealpath(
148 const wchar_t *path,
Victor Stinner015f4d82010-10-07 22:29:53 +0000149 wchar_t *resolved_path,
150 size_t resolved_path_size);
Victor Stinner4e314432010-10-07 21:45:39 +0000151#endif
152
153PyAPI_FUNC(wchar_t*) _Py_wgetcwd(
154 wchar_t *buf,
155 size_t size);
156
Victor Stinnerdaf45552013-08-28 00:53:59 +0200157PyAPI_FUNC(int) _Py_get_inheritable(int fd);
158
159PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,
160 int *atomic_flag_works);
161
Alexey Izbyshevc1e46e92018-02-06 09:09:34 +0300162PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable,
163 int *atomic_flag_works);
164
Victor Stinnerdaf45552013-08-28 00:53:59 +0200165PyAPI_FUNC(int) _Py_dup(int fd);
Victor Stinner1db9e7b2014-07-29 22:32:47 +0200166
167#ifndef MS_WINDOWS
168PyAPI_FUNC(int) _Py_get_blocking(int fd);
169
170PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
171#endif /* !MS_WINDOWS */
172
173#endif /* Py_LIMITED_API */
Victor Stinnerdaf45552013-08-28 00:53:59 +0200174
Victor Stinner4e314432010-10-07 21:45:39 +0000175#ifdef __cplusplus
176}
177#endif
Victor Stinner4e314432010-10-07 21:45:39 +0000178#endif /* !Py_FILEUTILS_H */