Merge branch 'rc/histogram-diff'
[git/jrn.git] / compat / win32.h
blob8ce91048deffc17bdf8d51672ddaa0c867052ac5
1 #ifndef WIN32_H
2 #define WIN32_H
4 /* common Win32 functions for MinGW and Cygwin */
5 #ifndef WIN32 /* Not defined by Cygwin */
6 #include <windows.h>
7 #endif
9 static inline int file_attr_to_st_mode (DWORD attr)
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;
21 static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata)
23 if (GetFileAttributesExA(fname, GetFileExInfoStandard, fdata))
24 return 0;
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;
41 #endif