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