Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:43

0001 #ifndef Py_INTERNAL_FILEUTILS_H
0002 #define Py_INTERNAL_FILEUTILS_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006 
0007 #ifndef Py_BUILD_CORE
0008 #  error "Py_BUILD_CORE must be defined to include this header"
0009 #endif
0010 
0011 #include <locale.h>   /* struct lconv */
0012 
0013 
0014 struct _fileutils_state {
0015     int force_ascii;
0016 };
0017 
0018 typedef enum {
0019     _Py_ERROR_UNKNOWN=0,
0020     _Py_ERROR_STRICT,
0021     _Py_ERROR_SURROGATEESCAPE,
0022     _Py_ERROR_REPLACE,
0023     _Py_ERROR_IGNORE,
0024     _Py_ERROR_BACKSLASHREPLACE,
0025     _Py_ERROR_SURROGATEPASS,
0026     _Py_ERROR_XMLCHARREFREPLACE,
0027     _Py_ERROR_OTHER
0028 } _Py_error_handler;
0029 
0030 PyAPI_FUNC(_Py_error_handler) _Py_GetErrorHandler(const char *errors);
0031 
0032 PyAPI_FUNC(int) _Py_DecodeLocaleEx(
0033     const char *arg,
0034     wchar_t **wstr,
0035     size_t *wlen,
0036     const char **reason,
0037     int current_locale,
0038     _Py_error_handler errors);
0039 
0040 PyAPI_FUNC(int) _Py_EncodeLocaleEx(
0041     const wchar_t *text,
0042     char **str,
0043     size_t *error_pos,
0044     const char **reason,
0045     int current_locale,
0046     _Py_error_handler errors);
0047 
0048 PyAPI_FUNC(char*) _Py_EncodeLocaleRaw(
0049     const wchar_t *text,
0050     size_t *error_pos);
0051 
0052 PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
0053 
0054 #if defined(MS_WINDOWS) || defined(__APPLE__)
0055     /* On Windows, the count parameter of read() is an int (bpo-9015, bpo-9611).
0056        On macOS 10.13, read() and write() with more than INT_MAX bytes
0057        fail with EINVAL (bpo-24658). */
0058 #   define _PY_READ_MAX  INT_MAX
0059 #   define _PY_WRITE_MAX INT_MAX
0060 #else
0061     /* write() should truncate the input to PY_SSIZE_T_MAX bytes,
0062        but it's safer to do it ourself to have a portable behaviour */
0063 #   define _PY_READ_MAX  PY_SSIZE_T_MAX
0064 #   define _PY_WRITE_MAX PY_SSIZE_T_MAX
0065 #endif
0066 
0067 #ifdef MS_WINDOWS
0068 struct _Py_stat_struct {
0069     uint64_t st_dev;
0070     uint64_t st_ino;
0071     unsigned short st_mode;
0072     int st_nlink;
0073     int st_uid;
0074     int st_gid;
0075     unsigned long st_rdev;
0076     __int64 st_size;
0077     time_t st_atime;
0078     int st_atime_nsec;
0079     time_t st_mtime;
0080     int st_mtime_nsec;
0081     time_t st_ctime;
0082     int st_ctime_nsec;
0083     time_t st_birthtime;
0084     int st_birthtime_nsec;
0085     unsigned long st_file_attributes;
0086     unsigned long st_reparse_tag;
0087     uint64_t st_ino_high;
0088 };
0089 #else
0090 #  define _Py_stat_struct stat
0091 #endif
0092 
0093 PyAPI_FUNC(int) _Py_fstat(
0094     int fd,
0095     struct _Py_stat_struct *status);
0096 
0097 PyAPI_FUNC(int) _Py_fstat_noraise(
0098     int fd,
0099     struct _Py_stat_struct *status);
0100 
0101 PyAPI_FUNC(int) _Py_stat(
0102     PyObject *path,
0103     struct stat *status);
0104 
0105 PyAPI_FUNC(int) _Py_open(
0106     const char *pathname,
0107     int flags);
0108 
0109 PyAPI_FUNC(int) _Py_open_noraise(
0110     const char *pathname,
0111     int flags);
0112 
0113 PyAPI_FUNC(FILE *) _Py_wfopen(
0114     const wchar_t *path,
0115     const wchar_t *mode);
0116 
0117 PyAPI_FUNC(Py_ssize_t) _Py_read(
0118     int fd,
0119     void *buf,
0120     size_t count);
0121 
0122 PyAPI_FUNC(Py_ssize_t) _Py_write(
0123     int fd,
0124     const void *buf,
0125     size_t count);
0126 
0127 PyAPI_FUNC(Py_ssize_t) _Py_write_noraise(
0128     int fd,
0129     const void *buf,
0130     size_t count);
0131 
0132 #ifdef HAVE_READLINK
0133 PyAPI_FUNC(int) _Py_wreadlink(
0134     const wchar_t *path,
0135     wchar_t *buf,
0136     /* Number of characters of 'buf' buffer
0137        including the trailing NUL character */
0138     size_t buflen);
0139 #endif
0140 
0141 #ifdef HAVE_REALPATH
0142 PyAPI_FUNC(wchar_t*) _Py_wrealpath(
0143     const wchar_t *path,
0144     wchar_t *resolved_path,
0145     /* Number of characters of 'resolved_path' buffer
0146        including the trailing NUL character */
0147     size_t resolved_path_len);
0148 #endif
0149 
0150 PyAPI_FUNC(wchar_t*) _Py_wgetcwd(
0151     wchar_t *buf,
0152     /* Number of characters of 'buf' buffer
0153        including the trailing NUL character */
0154     size_t buflen);
0155 
0156 PyAPI_FUNC(int) _Py_get_inheritable(int fd);
0157 
0158 PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,
0159                                     int *atomic_flag_works);
0160 
0161 PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable,
0162                                                int *atomic_flag_works);
0163 
0164 PyAPI_FUNC(int) _Py_dup(int fd);
0165 
0166 PyAPI_FUNC(int) _Py_get_blocking(int fd);
0167 
0168 PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
0169 
0170 #ifdef MS_WINDOWS
0171 PyAPI_FUNC(void*) _Py_get_osfhandle_noraise(int fd);
0172 
0173 PyAPI_FUNC(void*) _Py_get_osfhandle(int fd);
0174 
0175 PyAPI_FUNC(int) _Py_open_osfhandle_noraise(void *handle, int flags);
0176 
0177 PyAPI_FUNC(int) _Py_open_osfhandle(void *handle, int flags);
0178 #endif  /* MS_WINDOWS */
0179 
0180 // This is used after getting NULL back from Py_DecodeLocale().
0181 #define DECODE_LOCALE_ERR(NAME, LEN) \
0182     ((LEN) == (size_t)-2) \
0183      ? _PyStatus_ERR("cannot decode " NAME) \
0184      : _PyStatus_NO_MEMORY()
0185 
0186 PyAPI_DATA(int) _Py_HasFileSystemDefaultEncodeErrors;
0187 
0188 PyAPI_FUNC(int) _Py_DecodeUTF8Ex(
0189     const char *arg,
0190     Py_ssize_t arglen,
0191     wchar_t **wstr,
0192     size_t *wlen,
0193     const char **reason,
0194     _Py_error_handler errors);
0195 
0196 PyAPI_FUNC(int) _Py_EncodeUTF8Ex(
0197     const wchar_t *text,
0198     char **str,
0199     size_t *error_pos,
0200     const char **reason,
0201     int raw_malloc,
0202     _Py_error_handler errors);
0203 
0204 PyAPI_FUNC(wchar_t*) _Py_DecodeUTF8_surrogateescape(
0205     const char *arg,
0206     Py_ssize_t arglen,
0207     size_t *wlen);
0208 
0209 extern int
0210 _Py_wstat(const wchar_t *, struct stat *);
0211 
0212 PyAPI_FUNC(int) _Py_GetForceASCII(void);
0213 
0214 /* Reset "force ASCII" mode (if it was initialized).
0215 
0216    This function should be called when Python changes the LC_CTYPE locale,
0217    so the "force ASCII" mode can be detected again on the new locale
0218    encoding. */
0219 PyAPI_FUNC(void) _Py_ResetForceASCII(void);
0220 
0221 
0222 PyAPI_FUNC(int) _Py_GetLocaleconvNumeric(
0223     struct lconv *lc,
0224     PyObject **decimal_point,
0225     PyObject **thousands_sep);
0226 
0227 PyAPI_FUNC(void) _Py_closerange(int first, int last);
0228 
0229 PyAPI_FUNC(wchar_t*) _Py_GetLocaleEncoding(void);
0230 PyAPI_FUNC(PyObject*) _Py_GetLocaleEncodingObject(void);
0231 
0232 #ifdef HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION
0233 extern int _Py_LocaleUsesNonUnicodeWchar(void);
0234 
0235 extern wchar_t* _Py_DecodeNonUnicodeWchar(
0236     const wchar_t* native,
0237     Py_ssize_t size);
0238 
0239 extern int _Py_EncodeNonUnicodeWchar_InPlace(
0240     wchar_t* unicode,
0241     Py_ssize_t size);
0242 #endif
0243 
0244 extern int _Py_isabs(const wchar_t *path);
0245 extern int _Py_abspath(const wchar_t *path, wchar_t **abspath_p);
0246 #ifdef MS_WINDOWS
0247 extern int _PyOS_getfullpathname(const wchar_t *path, wchar_t **abspath_p);
0248 #endif
0249 extern wchar_t * _Py_join_relfile(const wchar_t *dirname,
0250                                   const wchar_t *relfile);
0251 extern int _Py_add_relfile(wchar_t *dirname,
0252                            const wchar_t *relfile,
0253                            size_t bufsize);
0254 extern size_t _Py_find_basename(const wchar_t *filename);
0255 PyAPI_FUNC(wchar_t*) _Py_normpath(wchar_t *path, Py_ssize_t size);
0256 extern wchar_t *_Py_normpath_and_size(wchar_t *path, Py_ssize_t size, Py_ssize_t *length);
0257 
0258 // The Windows Games API family does not provide these functions
0259 // so provide our own implementations. Remove them in case they get added
0260 // to the Games API family
0261 #if defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP)
0262 #include <winerror.h>
0263 
0264 extern HRESULT PathCchSkipRoot(const wchar_t *pszPath, const wchar_t **ppszRootEnd);
0265 #endif /* defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) */
0266 
0267 // Macros to protect CRT calls against instant termination when passed an
0268 // invalid parameter (bpo-23524). IPH stands for Invalid Parameter Handler.
0269 // Usage:
0270 //
0271 //      _Py_BEGIN_SUPPRESS_IPH
0272 //      ...
0273 //      _Py_END_SUPPRESS_IPH
0274 #if defined _MSC_VER && _MSC_VER >= 1900
0275 
0276 #  include <stdlib.h>   // _set_thread_local_invalid_parameter_handler()
0277 
0278    extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
0279 #  define _Py_BEGIN_SUPPRESS_IPH \
0280     { _invalid_parameter_handler _Py_old_handler = \
0281       _set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);
0282 #  define _Py_END_SUPPRESS_IPH \
0283     _set_thread_local_invalid_parameter_handler(_Py_old_handler); }
0284 #else
0285 #  define _Py_BEGIN_SUPPRESS_IPH
0286 #  define _Py_END_SUPPRESS_IPH
0287 #endif /* _MSC_VER >= 1900 */
0288 
0289 #ifdef __cplusplus
0290 }
0291 #endif
0292 #endif /* !Py_INTERNAL_FILEUTILS_H */