File indexing completed on 2025-01-30 10:18:06
0001 #ifndef Py_INTERNAL_FILEUTILS_WINDOWS_H
0002 #define Py_INTERNAL_FILEUTILS_WINDOWS_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 #ifdef MS_WINDOWS
0012
0013 #if !defined(NTDDI_WIN10_NI) || !(NTDDI_VERSION >= NTDDI_WIN10_NI)
0014 typedef struct _FILE_STAT_BASIC_INFORMATION {
0015 LARGE_INTEGER FileId;
0016 LARGE_INTEGER CreationTime;
0017 LARGE_INTEGER LastAccessTime;
0018 LARGE_INTEGER LastWriteTime;
0019 LARGE_INTEGER ChangeTime;
0020 LARGE_INTEGER AllocationSize;
0021 LARGE_INTEGER EndOfFile;
0022 ULONG FileAttributes;
0023 ULONG ReparseTag;
0024 ULONG NumberOfLinks;
0025 ULONG DeviceType;
0026 ULONG DeviceCharacteristics;
0027 ULONG Reserved;
0028 LARGE_INTEGER VolumeSerialNumber;
0029 FILE_ID_128 FileId128;
0030 } FILE_STAT_BASIC_INFORMATION;
0031
0032 typedef enum _FILE_INFO_BY_NAME_CLASS {
0033 FileStatByNameInfo,
0034 FileStatLxByNameInfo,
0035 FileCaseSensitiveByNameInfo,
0036 FileStatBasicByNameInfo,
0037 MaximumFileInfoByNameClass
0038 } FILE_INFO_BY_NAME_CLASS;
0039 #endif
0040
0041 typedef BOOL (WINAPI *PGetFileInformationByName)(
0042 PCWSTR FileName,
0043 FILE_INFO_BY_NAME_CLASS FileInformationClass,
0044 PVOID FileInfoBuffer,
0045 ULONG FileInfoBufferSize
0046 );
0047
0048 static inline BOOL _Py_GetFileInformationByName(
0049 PCWSTR FileName,
0050 FILE_INFO_BY_NAME_CLASS FileInformationClass,
0051 PVOID FileInfoBuffer,
0052 ULONG FileInfoBufferSize
0053 ) {
0054 static PGetFileInformationByName GetFileInformationByName = NULL;
0055 static int GetFileInformationByName_init = -1;
0056
0057 if (GetFileInformationByName_init < 0) {
0058 HMODULE hMod = LoadLibraryW(L"api-ms-win-core-file-l2-1-4");
0059 GetFileInformationByName_init = 0;
0060 if (hMod) {
0061 GetFileInformationByName = (PGetFileInformationByName)GetProcAddress(
0062 hMod, "GetFileInformationByName");
0063 if (GetFileInformationByName) {
0064 GetFileInformationByName_init = 1;
0065 } else {
0066 FreeLibrary(hMod);
0067 }
0068 }
0069 }
0070
0071 if (GetFileInformationByName_init <= 0) {
0072 SetLastError(ERROR_NOT_SUPPORTED);
0073 return FALSE;
0074 }
0075 return GetFileInformationByName(FileName, FileInformationClass, FileInfoBuffer, FileInfoBufferSize);
0076 }
0077
0078 static inline BOOL _Py_GetFileInformationByName_ErrorIsTrustworthy(int error)
0079 {
0080 switch(error) {
0081 case ERROR_FILE_NOT_FOUND:
0082 case ERROR_PATH_NOT_FOUND:
0083 case ERROR_NOT_READY:
0084 case ERROR_BAD_NET_NAME:
0085 case ERROR_BAD_NETPATH:
0086 case ERROR_BAD_PATHNAME:
0087 case ERROR_INVALID_NAME:
0088 case ERROR_FILENAME_EXCED_RANGE:
0089 return TRUE;
0090 case ERROR_NOT_SUPPORTED:
0091 return FALSE;
0092 }
0093 return FALSE;
0094 }
0095
0096 #endif
0097
0098 #endif