Code

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