Victor Stinner | 4e31443 | 2010-10-07 21:45:39 +0000 | [diff] [blame] | 1 | #ifndef Py_FILEUTILS_H |
| 2 | #define Py_FILEUTILS_H |
Victor Stinner | 4e31443 | 2010-10-07 21:45:39 +0000 | [diff] [blame] | 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Victor Stinner | 9fc57a3 | 2018-11-07 00:44:03 +0100 | [diff] [blame] | 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 | |
Victor Stinner | 3d4226a | 2018-08-29 22:21:32 +0200 | [diff] [blame] | 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); |
Victor Stinner | 3d4226a | 2018-08-29 22:21:32 +0200 | [diff] [blame] | 36 | |
Victor Stinner | 7ed7aea | 2018-01-15 10:45:49 +0100 | [diff] [blame] | 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, |
Victor Stinner | 3d4226a | 2018-08-29 22:21:32 +0200 | [diff] [blame] | 43 | _Py_error_handler errors); |
Victor Stinner | 7ed7aea | 2018-01-15 10:45:49 +0100 | [diff] [blame] | 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, |
Victor Stinner | 3d4226a | 2018-08-29 22:21:32 +0200 | [diff] [blame] | 51 | _Py_error_handler errors); |
Victor Stinner | 9bee329 | 2017-12-21 16:49:13 +0100 | [diff] [blame] | 52 | #endif |
| 53 | |
Serhiy Storchaka | 12ebbc7 | 2015-02-22 19:39:36 +0200 | [diff] [blame] | 54 | #ifndef Py_LIMITED_API |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 55 | PyAPI_FUNC(PyObject *) _Py_device_encoding(int); |
| 56 | |
Stéphane Wirtel | 74a8b6e | 2018-10-18 01:05:04 +0200 | [diff] [blame] | 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 | |
Steve Dower | f2f373f | 2015-02-21 08:44:05 -0800 | [diff] [blame] | 70 | #ifdef MS_WINDOWS |
| 71 | struct _Py_stat_struct { |
| 72 | unsigned long st_dev; |
Victor Stinner | 0f6d733 | 2017-03-09 17:34:28 +0100 | [diff] [blame] | 73 | uint64_t st_ino; |
Steve Dower | f2f373f | 2015-02-21 08:44:05 -0800 | [diff] [blame] | 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 | }; |
| 88 | #else |
| 89 | # define _Py_stat_struct stat |
| 90 | #endif |
| 91 | |
| 92 | PyAPI_FUNC(int) _Py_fstat( |
| 93 | int fd, |
Victor Stinner | e134a7f | 2015-03-30 10:09:31 +0200 | [diff] [blame] | 94 | struct _Py_stat_struct *status); |
| 95 | |
| 96 | PyAPI_FUNC(int) _Py_fstat_noraise( |
| 97 | int fd, |
| 98 | struct _Py_stat_struct *status); |
Steve Dower | f2f373f | 2015-02-21 08:44:05 -0800 | [diff] [blame] | 99 | |
Victor Stinner | 4e31443 | 2010-10-07 21:45:39 +0000 | [diff] [blame] | 100 | PyAPI_FUNC(int) _Py_stat( |
Victor Stinner | a4a7595 | 2010-10-07 22:23:10 +0000 | [diff] [blame] | 101 | PyObject *path, |
Victor Stinner | e134a7f | 2015-03-30 10:09:31 +0200 | [diff] [blame] | 102 | struct stat *status); |
Victor Stinner | 4e31443 | 2010-10-07 21:45:39 +0000 | [diff] [blame] | 103 | |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 104 | PyAPI_FUNC(int) _Py_open( |
| 105 | const char *pathname, |
| 106 | int flags); |
Victor Stinner | a555cfc | 2015-03-18 00:22:14 +0100 | [diff] [blame] | 107 | |
| 108 | PyAPI_FUNC(int) _Py_open_noraise( |
| 109 | const char *pathname, |
| 110 | int flags); |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 111 | |
Victor Stinner | 4e31443 | 2010-10-07 21:45:39 +0000 | [diff] [blame] | 112 | PyAPI_FUNC(FILE *) _Py_wfopen( |
| 113 | const wchar_t *path, |
| 114 | const wchar_t *mode); |
| 115 | |
| 116 | PyAPI_FUNC(FILE*) _Py_fopen( |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 117 | const char *pathname, |
| 118 | const char *mode); |
| 119 | |
| 120 | PyAPI_FUNC(FILE*) _Py_fopen_obj( |
Victor Stinner | a4a7595 | 2010-10-07 22:23:10 +0000 | [diff] [blame] | 121 | PyObject *path, |
Victor Stinner | 4e31443 | 2010-10-07 21:45:39 +0000 | [diff] [blame] | 122 | const char *mode); |
| 123 | |
Victor Stinner | 66aab0c | 2015-03-19 22:53:20 +0100 | [diff] [blame] | 124 | PyAPI_FUNC(Py_ssize_t) _Py_read( |
| 125 | int fd, |
| 126 | void *buf, |
| 127 | size_t count); |
| 128 | |
| 129 | PyAPI_FUNC(Py_ssize_t) _Py_write( |
| 130 | int fd, |
| 131 | const void *buf, |
| 132 | size_t count); |
| 133 | |
Victor Stinner | 82c3e45 | 2015-04-01 18:34:45 +0200 | [diff] [blame] | 134 | PyAPI_FUNC(Py_ssize_t) _Py_write_noraise( |
| 135 | int fd, |
| 136 | const void *buf, |
| 137 | size_t count); |
| 138 | |
Victor Stinner | 4e31443 | 2010-10-07 21:45:39 +0000 | [diff] [blame] | 139 | #ifdef HAVE_READLINK |
| 140 | PyAPI_FUNC(int) _Py_wreadlink( |
| 141 | const wchar_t *path, |
| 142 | wchar_t *buf, |
| 143 | size_t bufsiz); |
| 144 | #endif |
| 145 | |
| 146 | #ifdef HAVE_REALPATH |
| 147 | PyAPI_FUNC(wchar_t*) _Py_wrealpath( |
| 148 | const wchar_t *path, |
Victor Stinner | 015f4d8 | 2010-10-07 22:29:53 +0000 | [diff] [blame] | 149 | wchar_t *resolved_path, |
| 150 | size_t resolved_path_size); |
Victor Stinner | 4e31443 | 2010-10-07 21:45:39 +0000 | [diff] [blame] | 151 | #endif |
| 152 | |
| 153 | PyAPI_FUNC(wchar_t*) _Py_wgetcwd( |
| 154 | wchar_t *buf, |
| 155 | size_t size); |
| 156 | |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 157 | PyAPI_FUNC(int) _Py_get_inheritable(int fd); |
| 158 | |
| 159 | PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable, |
| 160 | int *atomic_flag_works); |
| 161 | |
Alexey Izbyshev | c1e46e9 | 2018-02-06 09:09:34 +0300 | [diff] [blame] | 162 | PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable, |
| 163 | int *atomic_flag_works); |
| 164 | |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 165 | PyAPI_FUNC(int) _Py_dup(int fd); |
Victor Stinner | 1db9e7b | 2014-07-29 22:32:47 +0200 | [diff] [blame] | 166 | |
| 167 | #ifndef MS_WINDOWS |
| 168 | PyAPI_FUNC(int) _Py_get_blocking(int fd); |
| 169 | |
| 170 | PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking); |
| 171 | #endif /* !MS_WINDOWS */ |
| 172 | |
| 173 | #endif /* Py_LIMITED_API */ |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 174 | |
Victor Stinner | 4e31443 | 2010-10-07 21:45:39 +0000 | [diff] [blame] | 175 | #ifdef __cplusplus |
| 176 | } |
| 177 | #endif |
Victor Stinner | 4e31443 | 2010-10-07 21:45:39 +0000 | [diff] [blame] | 178 | #endif /* !Py_FILEUTILS_H */ |