1 #ifndef WIN32_H 2 #define WIN32_H 3 4 /* common Win32 functions for MinGW and Cygwin */ 5 #ifndef GIT_WINDOWS_NATIVE /* Not defined for Cygwin */ 6 #include <windows.h> 7 #endif 8 file_attr_to_st_mode(DWORD attr)9static inline int file_attr_to_st_mode (DWORD attr) 10 { 11 int fMode = S_IREAD; 12 if (attr & FILE_ATTRIBUTE_DIRECTORY) 13 fMode |= S_IFDIR; 14 else 15 fMode |= S_IFREG; 16 if (!(attr & FILE_ATTRIBUTE_READONLY)) 17 fMode |= S_IWRITE; 18 return fMode; 19 } 20 get_file_attr(const char * fname,WIN32_FILE_ATTRIBUTE_DATA * fdata)21static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata) 22 { 23 if (GetFileAttributesExA(fname, GetFileExInfoStandard, fdata)) 24 return 0; 25 26 switch (GetLastError()) { 27 case ERROR_ACCESS_DENIED: 28 case ERROR_SHARING_VIOLATION: 29 case ERROR_LOCK_VIOLATION: 30 case ERROR_SHARING_BUFFER_EXCEEDED: 31 return EACCES; 32 case ERROR_BUFFER_OVERFLOW: 33 return ENAMETOOLONG; 34 case ERROR_NOT_ENOUGH_MEMORY: 35 return ENOMEM; 36 default: 37 return ENOENT; 38 } 39 } 40 41 #endif 42