Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/platform_file.h"
7 #include "base/logging.h"
9 namespace base {
11 PlatformFile CreatePlatformFile(const std::wstring& name,
12 int flags,
13 bool* created) {
14 DWORD disposition = 0;
16 if (flags & PLATFORM_FILE_OPEN)
17 disposition = OPEN_EXISTING;
19 if (flags & PLATFORM_FILE_CREATE) {
20 DCHECK(!disposition);
21 disposition = CREATE_NEW;
22 }
24 if (flags & PLATFORM_FILE_OPEN_ALWAYS) {
25 DCHECK(!disposition);
26 disposition = OPEN_ALWAYS;
27 }
29 if (flags & PLATFORM_FILE_CREATE_ALWAYS) {
30 DCHECK(!disposition);
31 disposition = CREATE_ALWAYS;
32 }
34 if (!disposition) {
35 NOTREACHED();
36 return NULL;
37 }
39 DWORD access = (flags & PLATFORM_FILE_READ) ? GENERIC_READ : 0;
40 if (flags & PLATFORM_FILE_WRITE)
41 access |= GENERIC_WRITE;
43 DWORD sharing = (flags & PLATFORM_FILE_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ;
44 if (!(flags & PLATFORM_FILE_EXCLUSIVE_WRITE))
45 sharing |= FILE_SHARE_WRITE;
47 DWORD create_flags = 0;
48 if (flags & PLATFORM_FILE_ASYNC)
49 create_flags |= FILE_FLAG_OVERLAPPED;
51 HANDLE file = CreateFile(name.c_str(), access, sharing, NULL, disposition,
52 create_flags, NULL);
54 if ((flags & PLATFORM_FILE_OPEN_ALWAYS) && created &&
55 INVALID_HANDLE_VALUE != file) {
56 *created = (ERROR_ALREADY_EXISTS != GetLastError());
57 }
59 return file;
60 }
62 } // namespace disk_cache