]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/stat.cpp
Return an empty Stat object for nonexistent files on Windows
[libs/core.git] / source / fs / stat.cpp
index f5e914eada807aa0ee356c736fd6a63fbecb3be0..d61081b95c9190732627c2e435223eb8f61ba73a 100644 (file)
@@ -94,7 +94,13 @@ Stat Stat::stat(const Path &path)
        HANDLE handle;
        handle = CreateFile(path.str().c_str(), 0, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
        if(handle==INVALID_HANDLE_VALUE)
-               throw system_error("CreateFile");
+       {
+               DWORD err = GetLastError();
+               if(err==ERROR_FILE_NOT_FOUND)
+                       return Stat();
+               else
+                       throw system_error("CreateFile", err);
+       }
 
        BY_HANDLE_FILE_INFORMATION info;
        if(!GetFileInformationByHandle(handle, &info))