builtin-clone: use strbuf in clone_local() and copy_or_link_directory()
[git/spearce.git] / compat / win32.h
blobc26384e595b4f23d5fef938b1136cc3a85469e56
1 /* common Win32 functions for MinGW and Cygwin */
2 #include <windows.h>
4 static inline int file_attr_to_st_mode (DWORD attr)
6 int fMode = S_IREAD;
7 if (attr & FILE_ATTRIBUTE_DIRECTORY)
8 fMode |= S_IFDIR;
9 else
10 fMode |= S_IFREG;
11 if (!(attr & FILE_ATTRIBUTE_READONLY))
12 fMode |= S_IWRITE;
13 return fMode;
16 static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata)
18 if (GetFileAttributesExA(fname, GetFileExInfoStandard, fdata))
19 return 0;
21 switch (GetLastError()) {
22 case ERROR_ACCESS_DENIED:
23 case ERROR_SHARING_VIOLATION:
24 case ERROR_LOCK_VIOLATION:
25 case ERROR_SHARING_BUFFER_EXCEEDED:
26 return EACCES;
27 case ERROR_BUFFER_OVERFLOW:
28 return ENAMETOOLONG;
29 case ERROR_NOT_ENOUGH_MEMORY:
30 return ENOMEM;
31 default:
32 return ENOENT;