Path: blob/main/Include/internal/pycore_fileutils_windows.h
12 views
#ifndef Py_INTERNAL_FILEUTILS_WINDOWS_H1#define Py_INTERNAL_FILEUTILS_WINDOWS_H2#ifdef __cplusplus3extern "C" {4#endif56#ifndef Py_BUILD_CORE7# error "Py_BUILD_CORE must be defined to include this header"8#endif910#ifdef MS_WINDOWS1112#if !defined(NTDDI_WIN10_NI) || !(NTDDI_VERSION >= NTDDI_WIN10_NI)13typedef struct _FILE_STAT_BASIC_INFORMATION {14LARGE_INTEGER FileId;15LARGE_INTEGER CreationTime;16LARGE_INTEGER LastAccessTime;17LARGE_INTEGER LastWriteTime;18LARGE_INTEGER ChangeTime;19LARGE_INTEGER AllocationSize;20LARGE_INTEGER EndOfFile;21ULONG FileAttributes;22ULONG ReparseTag;23ULONG NumberOfLinks;24ULONG DeviceType;25ULONG DeviceCharacteristics;26ULONG Reserved;27LARGE_INTEGER VolumeSerialNumber;28FILE_ID_128 FileId128;29} FILE_STAT_BASIC_INFORMATION;3031typedef enum _FILE_INFO_BY_NAME_CLASS {32FileStatByNameInfo,33FileStatLxByNameInfo,34FileCaseSensitiveByNameInfo,35FileStatBasicByNameInfo,36MaximumFileInfoByNameClass37} FILE_INFO_BY_NAME_CLASS;38#endif3940typedef BOOL (WINAPI *PGetFileInformationByName)(41PCWSTR FileName,42FILE_INFO_BY_NAME_CLASS FileInformationClass,43PVOID FileInfoBuffer,44ULONG FileInfoBufferSize45);4647static inline BOOL _Py_GetFileInformationByName(48PCWSTR FileName,49FILE_INFO_BY_NAME_CLASS FileInformationClass,50PVOID FileInfoBuffer,51ULONG FileInfoBufferSize52) {53static PGetFileInformationByName GetFileInformationByName = NULL;54static int GetFileInformationByName_init = -1;5556if (GetFileInformationByName_init < 0) {57HMODULE hMod = LoadLibraryW(L"api-ms-win-core-file-l2-1-4");58GetFileInformationByName_init = 0;59if (hMod) {60GetFileInformationByName = (PGetFileInformationByName)GetProcAddress(61hMod, "GetFileInformationByName");62if (GetFileInformationByName) {63GetFileInformationByName_init = 1;64} else {65FreeLibrary(hMod);66}67}68}6970if (GetFileInformationByName_init <= 0) {71SetLastError(ERROR_NOT_SUPPORTED);72return FALSE;73}74return GetFileInformationByName(FileName, FileInformationClass, FileInfoBuffer, FileInfoBufferSize);75}7677static inline BOOL _Py_GetFileInformationByName_ErrorIsTrustworthy(int error)78{79switch(error) {80case ERROR_FILE_NOT_FOUND:81case ERROR_PATH_NOT_FOUND:82case ERROR_NOT_READY:83case ERROR_BAD_NET_NAME:84case ERROR_BAD_NETPATH:85case ERROR_BAD_PATHNAME:86case ERROR_INVALID_NAME:87case ERROR_FILENAME_EXCED_RANGE:88return TRUE;89case ERROR_NOT_SUPPORTED:90return FALSE;91}92return FALSE;93}9495#endif9697#endif9899100