diff options
Diffstat (limited to 'libbb/win32.h')
-rw-r--r-- | libbb/win32.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libbb/win32.h b/libbb/win32.h new file mode 100644 index 000000000..c26384e59 --- /dev/null +++ b/libbb/win32.h | |||
@@ -0,0 +1,34 @@ | |||
1 | /* common Win32 functions for MinGW and Cygwin */ | ||
2 | #include <windows.h> | ||
3 | |||
4 | static inline int file_attr_to_st_mode (DWORD attr) | ||
5 | { | ||
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; | ||
14 | } | ||
15 | |||
16 | static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fdata) | ||
17 | { | ||
18 | if (GetFileAttributesExA(fname, GetFileExInfoStandard, fdata)) | ||
19 | return 0; | ||
20 | |||
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; | ||
33 | } | ||
34 | } | ||