diff options
author | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-03 17:18:14 +0000 |
---|---|---|
committer | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-03 17:18:14 +0000 |
commit | 21da6eb1f8a9740de03cb1435bf935f5a3609a37 (patch) | |
tree | 47e6bdd8db72ee4b66f526bbe79cbca74ef85560 /base/platform_file_win.cc | |
parent | 0a173a23af355f6b4eceeb18f28b453063e4287c (diff) | |
download | chromium_src-21da6eb1f8a9740de03cb1435bf935f5a3609a37.zip chromium_src-21da6eb1f8a9740de03cb1435bf935f5a3609a37.tar.gz chromium_src-21da6eb1f8a9740de03cb1435bf935f5a3609a37.tar.bz2 |
* Add write and read/write support to FileStream (renamed from FileInputStream).
* Moved net/disk_cache/os_file to base/platform_file.
Review URL: http://codereview.chromium.org/8843
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4454 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/platform_file_win.cc')
-rw-r--r-- | base/platform_file_win.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/base/platform_file_win.cc b/base/platform_file_win.cc new file mode 100644 index 0000000..987085d --- /dev/null +++ b/base/platform_file_win.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/platform_file.h" + +#include "base/logging.h" + +namespace base { + +PlatformFile CreatePlatformFile(const std::wstring& name, + int flags, + bool* created) { + DWORD disposition = 0; + + if (flags & PLATFORM_FILE_OPEN) + disposition = OPEN_EXISTING; + + if (flags & PLATFORM_FILE_CREATE) { + DCHECK(!disposition); + disposition = CREATE_NEW; + } + + if (flags & PLATFORM_FILE_OPEN_ALWAYS) { + DCHECK(!disposition); + disposition = OPEN_ALWAYS; + } + + if (flags & PLATFORM_FILE_CREATE_ALWAYS) { + DCHECK(!disposition); + disposition = CREATE_ALWAYS; + } + + if (!disposition) { + NOTREACHED(); + return NULL; + } + + DWORD access = (flags & PLATFORM_FILE_READ) ? GENERIC_READ : 0; + if (flags & PLATFORM_FILE_WRITE) + access |= GENERIC_WRITE; + + DWORD sharing = (flags & PLATFORM_FILE_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ; + if (!(flags & PLATFORM_FILE_EXCLUSIVE_WRITE)) + sharing |= FILE_SHARE_WRITE; + + DWORD create_flags = 0; + if (flags & PLATFORM_FILE_ASYNC) + create_flags |= FILE_FLAG_OVERLAPPED; + + HANDLE file = CreateFile(name.c_str(), access, sharing, NULL, disposition, + create_flags, NULL); + + if ((flags & PLATFORM_FILE_OPEN_ALWAYS) && created && + INVALID_HANDLE_VALUE != file) { + *created = (ERROR_ALREADY_EXISTS != GetLastError()); + } + + return file; +} + +} // namespace disk_cache + |