ipc/chromium/src/base/platform_file_win.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "base/platform_file.h"
michael@0 6
michael@0 7 #include "base/logging.h"
michael@0 8
michael@0 9 namespace base {
michael@0 10
michael@0 11 PlatformFile CreatePlatformFile(const std::wstring& name,
michael@0 12 int flags,
michael@0 13 bool* created) {
michael@0 14 DWORD disposition = 0;
michael@0 15
michael@0 16 if (flags & PLATFORM_FILE_OPEN)
michael@0 17 disposition = OPEN_EXISTING;
michael@0 18
michael@0 19 if (flags & PLATFORM_FILE_CREATE) {
michael@0 20 DCHECK(!disposition);
michael@0 21 disposition = CREATE_NEW;
michael@0 22 }
michael@0 23
michael@0 24 if (flags & PLATFORM_FILE_OPEN_ALWAYS) {
michael@0 25 DCHECK(!disposition);
michael@0 26 disposition = OPEN_ALWAYS;
michael@0 27 }
michael@0 28
michael@0 29 if (flags & PLATFORM_FILE_CREATE_ALWAYS) {
michael@0 30 DCHECK(!disposition);
michael@0 31 disposition = CREATE_ALWAYS;
michael@0 32 }
michael@0 33
michael@0 34 if (!disposition) {
michael@0 35 NOTREACHED();
michael@0 36 return NULL;
michael@0 37 }
michael@0 38
michael@0 39 DWORD access = (flags & PLATFORM_FILE_READ) ? GENERIC_READ : 0;
michael@0 40 if (flags & PLATFORM_FILE_WRITE)
michael@0 41 access |= GENERIC_WRITE;
michael@0 42
michael@0 43 DWORD sharing = (flags & PLATFORM_FILE_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ;
michael@0 44 if (!(flags & PLATFORM_FILE_EXCLUSIVE_WRITE))
michael@0 45 sharing |= FILE_SHARE_WRITE;
michael@0 46
michael@0 47 DWORD create_flags = 0;
michael@0 48 if (flags & PLATFORM_FILE_ASYNC)
michael@0 49 create_flags |= FILE_FLAG_OVERLAPPED;
michael@0 50
michael@0 51 HANDLE file = CreateFile(name.c_str(), access, sharing, NULL, disposition,
michael@0 52 create_flags, NULL);
michael@0 53
michael@0 54 if ((flags & PLATFORM_FILE_OPEN_ALWAYS) && created &&
michael@0 55 INVALID_HANDLE_VALUE != file) {
michael@0 56 *created = (ERROR_ALREADY_EXISTS != GetLastError());
michael@0 57 }
michael@0 58
michael@0 59 return file;
michael@0 60 }
michael@0 61
michael@0 62 } // namespace disk_cache

mercurial