compat / win32.hon commit Merge branch 'maint-1.6.0' into maint-1.6.1 (ff6e93f)
   1/* common Win32 functions for MinGW and Cygwin */
   2#include <windows.h>
   3
   4static 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
  16static 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}