]> git.ipfire.org Git - thirdparty/git.git/blame - compat/win32.h
Improve test for pthreads flag
[thirdparty/git.git] / compat / win32.h
CommitLineData
627735f9
MSO
1#ifndef WIN32_H
2#define WIN32_H
3
444dc903 4/* common Win32 functions for MinGW and Cygwin */
435bdf8c 5#ifndef WIN32 /* Not defined by Cygwin */
444dc903 6#include <windows.h>
435bdf8c 7#endif
444dc903
DP
8
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
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}
627735f9
MSO
40
41#endif