Marius Storm-Olsen | 627735f | 2009-09-16 10:20:18 +0200 | [diff] [blame] | 1 | #ifndef WIN32_H |
| 2 | #define WIN32_H |
| 3 | |
Dmitry Potapov | 444dc90 | 2008-09-27 12:43:01 +0400 | [diff] [blame] | 4 | /* common Win32 functions for MinGW and Cygwin */ |
Marius Storm-Olsen | 435bdf8 | 2009-09-16 10:20:26 +0200 | [diff] [blame] | 5 | #ifndef WIN32 /* Not defined by Cygwin */ |
Dmitry Potapov | 444dc90 | 2008-09-27 12:43:01 +0400 | [diff] [blame] | 6 | #include <windows.h> |
Marius Storm-Olsen | 435bdf8 | 2009-09-16 10:20:26 +0200 | [diff] [blame] | 7 | #endif |
Dmitry Potapov | 444dc90 | 2008-09-27 12:43:01 +0400 | [diff] [blame] | 8 | |
| 9 | static 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 | |
| 21 | static 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 | } |
Marius Storm-Olsen | 627735f | 2009-09-16 10:20:18 +0200 | [diff] [blame] | 40 | |
| 41 | #endif |