diff options
author | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 19:30:27 +0000 |
---|---|---|
committer | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 19:30:27 +0000 |
commit | ed65fece343181e91b4d36e161434cc763475de7 (patch) | |
tree | 27af7d7cb8a12f65b24dba3ebd5ede3d592e2d8e /base/platform_file_win.cc | |
parent | 2d723bc66e60bedd617ebd464996ee2388c0c365 (diff) | |
download | chromium_src-ed65fece343181e91b4d36e161434cc763475de7.zip chromium_src-ed65fece343181e91b4d36e161434cc763475de7.tar.gz chromium_src-ed65fece343181e91b4d36e161434cc763475de7.tar.bz2 |
Add an optional parameter to CreatePlatformFile() to report the type
of error that occured while trying to open/create a file.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/3223007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58045 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/platform_file_win.cc')
-rw-r--r-- | base/platform_file_win.cc | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/base/platform_file_win.cc b/base/platform_file_win.cc index 1143487..c4b3c08 100644 --- a/base/platform_file_win.cc +++ b/base/platform_file_win.cc @@ -11,7 +11,8 @@ namespace base { PlatformFile CreatePlatformFile(const FilePath& name, int flags, - bool* created) { + bool* created, + PlatformFileError* error_code) { DWORD disposition = 0; if (flags & PLATFORM_FILE_OPEN) @@ -32,6 +33,12 @@ PlatformFile CreatePlatformFile(const FilePath& name, disposition = CREATE_ALWAYS; } + if (flags & PLATFORM_FILE_TRUNCATE) { + DCHECK(!disposition); + DCHECK(flags & PLATFORM_FILE_WRITE); + disposition = TRUNCATE_EXISTING; + } + if (!disposition) { NOTREACHED(); return NULL; @@ -63,12 +70,33 @@ PlatformFile CreatePlatformFile(const FilePath& name, *created = (ERROR_ALREADY_EXISTS != GetLastError()); } + if ((file == kInvalidPlatformFileValue) && error_code) { + DWORD last_error = GetLastError(); + switch (last_error) { + case ERROR_SHARING_VIOLATION: + *error_code = PLATFORM_FILE_ERROR_IN_USE; + break; + case ERROR_FILE_EXISTS: + *error_code = PLATFORM_FILE_ERROR_EXISTS; + break; + case ERROR_FILE_NOT_FOUND: + *error_code = PLATFORM_FILE_ERROR_NOT_FOUND; + break; + case ERROR_ACCESS_DENIED: + *error_code = PLATFORM_FILE_ERROR_ACCESS_DENIED; + break; + default: + *error_code = PLATFORM_FILE_ERROR_FAILED; + } + } + return file; } PlatformFile CreatePlatformFile(const std::wstring& name, int flags, bool* created) { - return CreatePlatformFile(FilePath::FromWStringHack(name), flags, created); + return CreatePlatformFile(FilePath::FromWStringHack(name), flags, + created, NULL); } bool ClosePlatformFile(PlatformFile file) { |