| 980 | } |
| 981 | |
| 982 | Result<bool> FileExists(const PlatformFilename& path) { |
| 983 | #ifdef _WIN32 |
| 984 | if (GetFileAttributesW(path.ToNative().c_str()) != INVALID_FILE_ATTRIBUTES) { |
| 985 | return true; |
| 986 | } else { |
| 987 | int errnum = GetLastError(); |
| 988 | if (errnum != ERROR_PATH_NOT_FOUND && errnum != ERROR_FILE_NOT_FOUND) { |
| 989 | return IOErrorFromWinError(GetLastError(), "Failed getting information for path '", |
| 990 | path.ToString(), "'"); |
| 991 | } |
| 992 | return false; |
| 993 | } |
| 994 | #else |
| 995 | struct stat st; |
| 996 | if (stat(path.ToNative().c_str(), &st) == 0) { |
| 997 | return true; |
| 998 | } else { |
| 999 | if (errno != ENOENT && errno != ENOTDIR) { |
| 1000 | return IOErrorFromErrno(errno, "Failed getting information for path '", |
| 1001 | path.ToString(), "'"); |
| 1002 | } |
| 1003 | return false; |
| 1004 | } |
| 1005 | #endif |
| 1006 | } |
| 1007 | |
| 1008 | // |
| 1009 | // Creating and destroying file descriptors |