blob: c05ff43f516394a1654f330fe1479fb9d32d7000 [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
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +02008#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
Victor Stinnerf6a271a2014-08-01 12:28:48 +02009PyAPI_FUNC(wchar_t *) Py_DecodeLocale(
Victor Stinner168e1172010-10-16 23:16:16 +000010 const char *arg,
11 size_t *size);
Victor Stinner4e314432010-10-07 21:45:39 +000012
Victor Stinnerf6a271a2014-08-01 12:28:48 +020013PyAPI_FUNC(char*) Py_EncodeLocale(
Victor Stinner2f02a512010-11-08 22:43:46 +000014 const wchar_t *text,
15 size_t *error_pos);
Victor Stinner9dd76202017-12-21 16:20:32 +010016
17PyAPI_FUNC(char*) _Py_EncodeLocaleRaw(
18 const wchar_t *text,
19 size_t *error_pos);
Serhiy Storchaka34d0ac82016-12-27 14:57:39 +020020#endif
Victor Stinner4e314432010-10-07 21:45:39 +000021
Victor Stinner9bee3292017-12-21 16:49:13 +010022#ifdef Py_BUILD_CORE
Victor Stinner7ed7aea2018-01-15 10:45:49 +010023PyAPI_FUNC(int) _Py_DecodeUTF8Ex(
Victor Stinner2cba6b82018-01-10 22:46:15 +010024 const char *arg,
Victor Stinner7ed7aea2018-01-15 10:45:49 +010025 Py_ssize_t arglen,
26 wchar_t **wstr,
27 size_t *wlen,
28 const char **reason,
29 int surrogateescape);
Victor Stinner2cba6b82018-01-10 22:46:15 +010030
Victor Stinner7ed7aea2018-01-15 10:45:49 +010031PyAPI_FUNC(int) _Py_EncodeUTF8Ex(
Victor Stinner2cba6b82018-01-10 22:46:15 +010032 const wchar_t *text,
Victor Stinner7ed7aea2018-01-15 10:45:49 +010033 char **str,
34 size_t *error_pos,
35 const char **reason,
36 int raw_malloc,
37 int surrogateescape);
38
39PyAPI_FUNC(wchar_t*) _Py_DecodeUTF8_surrogateescape(
40 const char *arg,
41 Py_ssize_t arglen);
42
43PyAPI_FUNC(int) _Py_DecodeLocaleEx(
44 const char *arg,
45 wchar_t **wstr,
46 size_t *wlen,
47 const char **reason,
48 int current_locale,
49 int surrogateescape);
50
51PyAPI_FUNC(int) _Py_EncodeLocaleEx(
52 const wchar_t *text,
53 char **str,
54 size_t *error_pos,
55 const char **reason,
56 int current_locale,
57 int surrogateescape);
Victor Stinner9bee3292017-12-21 16:49:13 +010058#endif
59
Serhiy Storchaka12ebbc72015-02-22 19:39:36 +020060#ifndef Py_LIMITED_API
Serhiy Storchaka9fab79b2016-09-11 11:03:14 +030061PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
62
Miss Islington (bot)178d1c02018-10-17 23:58:40 -070063#if defined(MS_WINDOWS) || defined(__APPLE__)
64 /* On Windows, the count parameter of read() is an int (bpo-9015, bpo-9611).
65 On macOS 10.13, read() and write() with more than INT_MAX bytes
66 fail with EINVAL (bpo-24658). */
67# define _PY_READ_MAX INT_MAX
68# define _PY_WRITE_MAX INT_MAX
69#else
70 /* write() should truncate the input to PY_SSIZE_T_MAX bytes,
71 but it's safer to do it ourself to have a portable behaviour */
72# define _PY_READ_MAX PY_SSIZE_T_MAX
73# define _PY_WRITE_MAX PY_SSIZE_T_MAX
74#endif
75
Steve Dowerf2f373f2015-02-21 08:44:05 -080076#ifdef MS_WINDOWS
77struct _Py_stat_struct {
78 unsigned long st_dev;
Victor Stinner0f6d7332017-03-09 17:34:28 +010079 uint64_t st_ino;
Steve Dowerf2f373f2015-02-21 08:44:05 -080080 unsigned short st_mode;
81 int st_nlink;
82 int st_uid;
83 int st_gid;
84 unsigned long st_rdev;
85 __int64 st_size;
86 time_t st_atime;
87 int st_atime_nsec;
88 time_t st_mtime;
89 int st_mtime_nsec;
90 time_t st_ctime;
91 int st_ctime_nsec;
92 unsigned long st_file_attributes;
93};
94#else
95# define _Py_stat_struct stat
96#endif
97
98PyAPI_FUNC(int) _Py_fstat(
99 int fd,
Victor Stinnere134a7f2015-03-30 10:09:31 +0200100 struct _Py_stat_struct *status);
101
102PyAPI_FUNC(int) _Py_fstat_noraise(
103 int fd,
104 struct _Py_stat_struct *status);
Steve Dowerf2f373f2015-02-21 08:44:05 -0800105
Victor Stinner4e314432010-10-07 21:45:39 +0000106PyAPI_FUNC(int) _Py_stat(
Victor Stinnera4a75952010-10-07 22:23:10 +0000107 PyObject *path,
Victor Stinnere134a7f2015-03-30 10:09:31 +0200108 struct stat *status);
Victor Stinner4e314432010-10-07 21:45:39 +0000109
Victor Stinnerdaf45552013-08-28 00:53:59 +0200110PyAPI_FUNC(int) _Py_open(
111 const char *pathname,
112 int flags);
Victor Stinnera555cfc2015-03-18 00:22:14 +0100113
114PyAPI_FUNC(int) _Py_open_noraise(
115 const char *pathname,
116 int flags);
Victor Stinnerdaf45552013-08-28 00:53:59 +0200117
Victor Stinner4e314432010-10-07 21:45:39 +0000118PyAPI_FUNC(FILE *) _Py_wfopen(
119 const wchar_t *path,
120 const wchar_t *mode);
121
122PyAPI_FUNC(FILE*) _Py_fopen(
Victor Stinnerdaf45552013-08-28 00:53:59 +0200123 const char *pathname,
124 const char *mode);
125
126PyAPI_FUNC(FILE*) _Py_fopen_obj(
Victor Stinnera4a75952010-10-07 22:23:10 +0000127 PyObject *path,
Victor Stinner4e314432010-10-07 21:45:39 +0000128 const char *mode);
129
Victor Stinner66aab0c2015-03-19 22:53:20 +0100130PyAPI_FUNC(Py_ssize_t) _Py_read(
131 int fd,
132 void *buf,
133 size_t count);
134
135PyAPI_FUNC(Py_ssize_t) _Py_write(
136 int fd,
137 const void *buf,
138 size_t count);
139
Victor Stinner82c3e452015-04-01 18:34:45 +0200140PyAPI_FUNC(Py_ssize_t) _Py_write_noraise(
141 int fd,
142 const void *buf,
143 size_t count);
144
Victor Stinner4e314432010-10-07 21:45:39 +0000145#ifdef HAVE_READLINK
146PyAPI_FUNC(int) _Py_wreadlink(
147 const wchar_t *path,
148 wchar_t *buf,
149 size_t bufsiz);
150#endif
151
152#ifdef HAVE_REALPATH
153PyAPI_FUNC(wchar_t*) _Py_wrealpath(
154 const wchar_t *path,
Victor Stinner015f4d82010-10-07 22:29:53 +0000155 wchar_t *resolved_path,
156 size_t resolved_path_size);
Victor Stinner4e314432010-10-07 21:45:39 +0000157#endif
158
159PyAPI_FUNC(wchar_t*) _Py_wgetcwd(
160 wchar_t *buf,
161 size_t size);
162
Victor Stinnerdaf45552013-08-28 00:53:59 +0200163PyAPI_FUNC(int) _Py_get_inheritable(int fd);
164
165PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,
166 int *atomic_flag_works);
167
Miss Islington (bot)2bb0bfa2018-02-05 22:31:22 -0800168PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable,
169 int *atomic_flag_works);
170
Victor Stinnerdaf45552013-08-28 00:53:59 +0200171PyAPI_FUNC(int) _Py_dup(int fd);
Victor Stinner1db9e7b2014-07-29 22:32:47 +0200172
173#ifndef MS_WINDOWS
174PyAPI_FUNC(int) _Py_get_blocking(int fd);
175
176PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
177#endif /* !MS_WINDOWS */
178
Victor Stinnercb064fc2018-01-15 15:58:02 +0100179PyAPI_FUNC(int) _Py_GetLocaleconvNumeric(
180 PyObject **decimal_point,
181 PyObject **thousands_sep,
182 const char **grouping);
183
Victor Stinner1db9e7b2014-07-29 22:32:47 +0200184#endif /* Py_LIMITED_API */
Victor Stinnerdaf45552013-08-28 00:53:59 +0200185
Victor Stinner4e314432010-10-07 21:45:39 +0000186#ifdef __cplusplus
187}
188#endif
189
190#endif /* !Py_FILEUTILS_H */