Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
pycore_fileutils.h321 linesDownload Raw Back to internal
1#ifndef Py_INTERNAL_FILEUTILS_H2#define Py_INTERNAL_FILEUTILS_H3#ifdef __cplusplus4extern "C" {5#endif6 7#ifndef Py_BUILD_CORE8#  error "this header requires Py_BUILD_CORE define"9#endif10 11#include <locale.h>               // struct lconv12#include "pycore_interp_structs.h" // _Py_error_handler13 14 15/* A routine to check if a file descriptor can be select()-ed. */16#ifdef _MSC_VER17    /* On Windows, any socket fd can be select()-ed, no matter how high */18    #define _PyIsSelectable_fd(FD) (1)19#else20    #define _PyIsSelectable_fd(FD) ((unsigned int)(FD) < (unsigned int)FD_SETSIZE)21#endif22 23// Export for '_testinternalcapi' shared extension24PyAPI_FUNC(_Py_error_handler) _Py_GetErrorHandler(const char *errors);25 26// Export for '_testinternalcapi' shared extension27PyAPI_FUNC(int) _Py_DecodeLocaleEx(28    const char *arg,29    wchar_t **wstr,30    size_t *wlen,31    const char **reason,32    int current_locale,33    _Py_error_handler errors);34 35// Export for '_testinternalcapi' shared extension36PyAPI_FUNC(int) _Py_EncodeLocaleEx(37    const wchar_t *text,38    char **str,39    size_t *error_pos,40    const char **reason,41    int current_locale,42    _Py_error_handler errors);43 44extern char* _Py_EncodeLocaleRaw(45    const wchar_t *text,46    size_t *error_pos);47 48extern PyObject* _Py_device_encoding(int);49 50#if defined(MS_WINDOWS) || defined(__APPLE__)51    /* On Windows, the count parameter of read() is an int (bpo-9015, bpo-9611).52       On macOS 10.13, read() and write() with more than INT_MAX bytes53       fail with EINVAL (bpo-24658). */54#   define _PY_READ_MAX  INT_MAX55#   define _PY_WRITE_MAX INT_MAX56#else57    /* write() should truncate the input to PY_SSIZE_T_MAX bytes,58       but it's safer to do it ourself to have a portable behaviour */59#   define _PY_READ_MAX  PY_SSIZE_T_MAX60#   define _PY_WRITE_MAX PY_SSIZE_T_MAX61#endif62 63#ifdef MS_WINDOWS64struct _Py_stat_struct {65    uint64_t st_dev;66    uint64_t st_ino;67    unsigned short st_mode;68    int st_nlink;69    int st_uid;70    int st_gid;71    unsigned long st_rdev;72    __int64 st_size;73    time_t st_atime;74    int st_atime_nsec;75    time_t st_mtime;76    int st_mtime_nsec;77    time_t st_ctime;78    int st_ctime_nsec;79    time_t st_birthtime;80    int st_birthtime_nsec;81    unsigned long st_file_attributes;82    unsigned long st_reparse_tag;83    uint64_t st_ino_high;84};85#else86#  define _Py_stat_struct stat87#endif88 89// Export for 'mmap' shared extension90PyAPI_FUNC(int) _Py_fstat(91    int fd,92    struct _Py_stat_struct *status);93 94// Export for 'mmap' shared extension95PyAPI_FUNC(int) _Py_fstat_noraise(96    int fd,97    struct _Py_stat_struct *status);98 99// Export for '_tkinter' shared extension100PyAPI_FUNC(int) _Py_stat(101    PyObject *path,102    struct stat *status);103 104// Export for 'select' shared extension (Solaris newDevPollObject())105PyAPI_FUNC(int) _Py_open(106    const char *pathname,107    int flags);108 109// Export for '_posixsubprocess' shared extension110PyAPI_FUNC(int) _Py_open_noraise(111    const char *pathname,112    int flags);113 114extern FILE* _Py_wfopen(115    const wchar_t *path,116    const wchar_t *mode);117 118extern Py_ssize_t _Py_read(119    int fd,120    void *buf,121    size_t count);122 123// Export for 'select' shared extension (Solaris devpoll_flush())124PyAPI_FUNC(Py_ssize_t) _Py_write(125    int fd,126    const void *buf,127    size_t count);128 129// Export for '_posixsubprocess' shared extension130PyAPI_FUNC(Py_ssize_t) _Py_write_noraise(131    int fd,132    const void *buf,133    size_t count);134 135#ifdef HAVE_READLINK136extern int _Py_wreadlink(137    const wchar_t *path,138    wchar_t *buf,139    /* Number of characters of 'buf' buffer140       including the trailing NUL character */141    size_t buflen);142#endif143 144#ifdef HAVE_REALPATH145extern wchar_t* _Py_wrealpath(146    const wchar_t *path,147    wchar_t *resolved_path,148    /* Number of characters of 'resolved_path' buffer149       including the trailing NUL character */150    size_t resolved_path_len);151#endif152 153extern wchar_t* _Py_wgetcwd(154    wchar_t *buf,155    /* Number of characters of 'buf' buffer156       including the trailing NUL character */157    size_t buflen);158 159extern int _Py_get_inheritable(int fd);160 161// Export for '_socket' shared extension162PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,163                                    int *atomic_flag_works);164 165// Export for '_posixsubprocess' shared extension166PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable,167                                               int *atomic_flag_works);168 169// Export for '_socket' shared extension170PyAPI_FUNC(int) _Py_dup(int fd);171 172extern int _Py_get_blocking(int fd);173 174extern int _Py_set_blocking(int fd, int blocking);175 176#ifdef MS_WINDOWS177extern void* _Py_get_osfhandle_noraise(int fd);178 179// Export for '_testconsole' shared extension180PyAPI_FUNC(void*) _Py_get_osfhandle(int fd);181 182extern int _Py_open_osfhandle_noraise(void *handle, int flags);183 184extern int _Py_open_osfhandle(void *handle, int flags);185#endif  /* MS_WINDOWS */186 187// This is used after getting NULL back from Py_DecodeLocale().188#define DECODE_LOCALE_ERR(NAME, LEN) \189    ((LEN) == (size_t)-2) \190     ? _PyStatus_ERR("cannot decode " NAME) \191     : _PyStatus_NO_MEMORY()192 193extern int _Py_HasFileSystemDefaultEncodeErrors;194 195extern int _Py_DecodeUTF8Ex(196    const char *arg,197    Py_ssize_t arglen,198    wchar_t **wstr,199    size_t *wlen,200    const char **reason,201    _Py_error_handler errors);202 203extern int _Py_EncodeUTF8Ex(204    const wchar_t *text,205    char **str,206    size_t *error_pos,207    const char **reason,208    int raw_malloc,209    _Py_error_handler errors);210 211extern wchar_t* _Py_DecodeUTF8_surrogateescape(212    const char *arg,213    Py_ssize_t arglen,214    size_t *wlen);215 216extern int217_Py_wstat(const wchar_t *, struct stat *);218 219extern int _Py_GetForceASCII(void);220 221/* Reset "force ASCII" mode (if it was initialized).222 223   This function should be called when Python changes the LC_CTYPE locale,224   so the "force ASCII" mode can be detected again on the new locale225   encoding. */226extern void _Py_ResetForceASCII(void);227 228 229extern int _Py_GetLocaleconvNumeric(230    struct lconv *lc,231    PyObject **decimal_point,232    PyObject **thousands_sep);233 234// Export for '_posixsubprocess' (on macOS)235PyAPI_FUNC(void) _Py_closerange(int first, int last);236 237extern wchar_t* _Py_GetLocaleEncoding(void);238extern PyObject* _Py_GetLocaleEncodingObject(void);239 240#ifdef HAVE_NON_UNICODE_WCHAR_T_REPRESENTATION241extern int _Py_LocaleUsesNonUnicodeWchar(void);242 243extern wchar_t* _Py_DecodeNonUnicodeWchar(244    const wchar_t* native,245    Py_ssize_t size);246 247extern int _Py_EncodeNonUnicodeWchar_InPlace(248    wchar_t* unicode,249    Py_ssize_t size);250#endif251 252extern int _Py_isabs(const wchar_t *path);253extern int _Py_abspath(const wchar_t *path, wchar_t **abspath_p);254#ifdef MS_WINDOWS255extern int _PyOS_getfullpathname(const wchar_t *path, wchar_t **abspath_p);256#endif257extern wchar_t* _Py_join_relfile(const wchar_t *dirname,258                                 const wchar_t *relfile);259extern int _Py_add_relfile(wchar_t *dirname,260                           const wchar_t *relfile,261                           size_t bufsize);262extern size_t _Py_find_basename(const wchar_t *filename);263 264// Export for '_testinternalcapi' shared extension265PyAPI_FUNC(wchar_t*) _Py_normpath(wchar_t *path, Py_ssize_t size);266 267extern wchar_t *_Py_normpath_and_size(wchar_t *path, Py_ssize_t size, Py_ssize_t *length);268 269// The Windows Games API family does not provide these functions270// so provide our own implementations. Remove them in case they get added271// to the Games API family272#if defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP)273#include <winerror.h>             // HRESULT274 275extern HRESULT PathCchSkipRoot(const wchar_t *pszPath, const wchar_t **ppszRootEnd);276#endif /* defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) */277 278extern void _Py_skiproot(const wchar_t *path, Py_ssize_t size, Py_ssize_t *drvsize, Py_ssize_t *rootsize);279 280// Macros to protect CRT calls against instant termination when passed an281// invalid parameter (bpo-23524). IPH stands for Invalid Parameter Handler.282// Usage:283//284//      _Py_BEGIN_SUPPRESS_IPH285//      ...286//      _Py_END_SUPPRESS_IPH287#if defined _MSC_VER && _MSC_VER >= 1900288 289#  include <stdlib.h>   // _set_thread_local_invalid_parameter_handler()290 291   extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;292#  define _Py_BEGIN_SUPPRESS_IPH \293    { _invalid_parameter_handler _Py_old_handler = \294      _set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler);295#  define _Py_END_SUPPRESS_IPH \296    _set_thread_local_invalid_parameter_handler(_Py_old_handler); }297#else298#  define _Py_BEGIN_SUPPRESS_IPH299#  define _Py_END_SUPPRESS_IPH300#endif /* _MSC_VER >= 1900 */301 302// Export for 'select' shared extension (Argument Clinic code)303PyAPI_FUNC(int) _PyLong_FileDescriptor_Converter(PyObject *, void *);304 305// Export for test_peg_generator306PyAPI_FUNC(char*) _Py_UniversalNewlineFgetsWithSize(char *, int, FILE*, PyObject *, size_t*);307 308extern int _PyFile_Flush(PyObject *);309 310#ifndef MS_WINDOWS311extern int _Py_GetTicksPerSecond(long *ticks_per_second);312#endif313 314// Export for '_testcapi' shared extension315PyAPI_FUNC(int) _Py_IsValidFD(int fd);316 317#ifdef __cplusplus318}319#endif320#endif /* !Py_INTERNAL_FILEUTILS_H */321 
codekingpro/portable-devtools · Team Ai