title: How does _stat() under Windows exactly work
body: <p>In my code I try to get the permissions for a file with _stat(). Currently I want to run it under Windows. The method is as follows:</p>
  
  <pre><code>bool CFile::Private::checkPermissions(std::string sFilename, CFile::EOpenmode iOpenmode)
  {
    std::string sErrMsg = "";
    bool bResult = true;
    struct _stat buf;
    int iResult = 0;
  
    // Get data associated with "crt_stat.c": 
    iResult = _stat( sFilename.c_str(), &amp;buf );
  
    // Check if statistics are valid: 
    if( iResult != 0 )
    {
      switch (errno)
      {
        case ENOENT:
          sErrMsg = "File: " + sFilename + " not found.";
          break;
        case EINVAL:
          sErrMsg = "Invalid parameter to _stat(filename, &amp;buf).";
          break;
        default:
          /* Should never be reached. */
          sErrMsg = "Unexpected error in _stat(filename, &amp;buf).";
      }
      throw std::runtime_error(sErrMsg);
    }
    else
    {
      if((iOpenmode &amp; CFile::Read) &amp;&amp; (!(buf.st_mode &amp; S_IREAD)))
      {
        bResult = false;
      }
      if((iOpenmode &amp; CFile::Write) &amp;&amp; (!(buf.st_mode &amp; S_IWRITE)))
      {
        bResult = false;
      }
    }
    return bResult;
  }
  </code></pre>
  
  <p>The only way to get 'false' for permission is to set the file's attribute 'read only'. Instead of this, set the security properties of the user (reject writing and reading) will get 'true' for checkPermissions(...). How to check both, the attributes and the user permissions for Windows?</p>
  
  <p>Rumo</p>