ipc/chromium/src/base/platform_file_win.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/platform_file_win.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#include "base/platform_file.h"
     1.9 +
    1.10 +#include "base/logging.h"
    1.11 +
    1.12 +namespace base {
    1.13 +
    1.14 +PlatformFile CreatePlatformFile(const std::wstring& name,
    1.15 +                                int flags,
    1.16 +                                bool* created) {
    1.17 +  DWORD disposition = 0;
    1.18 +
    1.19 +  if (flags & PLATFORM_FILE_OPEN)
    1.20 +    disposition = OPEN_EXISTING;
    1.21 +
    1.22 +  if (flags & PLATFORM_FILE_CREATE) {
    1.23 +    DCHECK(!disposition);
    1.24 +    disposition = CREATE_NEW;
    1.25 +  }
    1.26 +
    1.27 +  if (flags & PLATFORM_FILE_OPEN_ALWAYS) {
    1.28 +    DCHECK(!disposition);
    1.29 +    disposition = OPEN_ALWAYS;
    1.30 +  }
    1.31 +
    1.32 +  if (flags & PLATFORM_FILE_CREATE_ALWAYS) {
    1.33 +    DCHECK(!disposition);
    1.34 +    disposition = CREATE_ALWAYS;
    1.35 +  }
    1.36 +
    1.37 +  if (!disposition) {
    1.38 +    NOTREACHED();
    1.39 +    return NULL;
    1.40 +  }
    1.41 +
    1.42 +  DWORD access = (flags & PLATFORM_FILE_READ) ? GENERIC_READ : 0;
    1.43 +  if (flags & PLATFORM_FILE_WRITE)
    1.44 +    access |= GENERIC_WRITE;
    1.45 +
    1.46 +  DWORD sharing = (flags & PLATFORM_FILE_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ;
    1.47 +  if (!(flags & PLATFORM_FILE_EXCLUSIVE_WRITE))
    1.48 +    sharing |= FILE_SHARE_WRITE;
    1.49 +
    1.50 +  DWORD create_flags = 0;
    1.51 +  if (flags & PLATFORM_FILE_ASYNC)
    1.52 +    create_flags |= FILE_FLAG_OVERLAPPED;
    1.53 +
    1.54 +  HANDLE file = CreateFile(name.c_str(), access, sharing, NULL, disposition,
    1.55 +                           create_flags, NULL);
    1.56 +
    1.57 +  if ((flags & PLATFORM_FILE_OPEN_ALWAYS) && created &&
    1.58 +      INVALID_HANDLE_VALUE != file) {
    1.59 +    *created = (ERROR_ALREADY_EXISTS != GetLastError());
    1.60 +  }
    1.61 +
    1.62 +  return file;
    1.63 +}
    1.64 +
    1.65 +}  // namespace disk_cache

mercurial