platform_file.h revision c7f5f8508d98d5952d42ed7648c2a8f30a4da156
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.
4
5#ifndef BASE_PLATFORM_FILE_H_
6#define BASE_PLATFORM_FILE_H_
7
8#include "build/build_config.h"
9#if defined(OS_WIN)
10#include <windows.h>
11#endif
12
13#include <string>
14
15class FilePath;
16
17namespace base {
18
19#if defined(OS_WIN)
20typedef HANDLE PlatformFile;
21const PlatformFile kInvalidPlatformFileValue = INVALID_HANDLE_VALUE;
22#elif defined(OS_POSIX)
23typedef int PlatformFile;
24const PlatformFile kInvalidPlatformFileValue = -1;
25#endif
26
27enum PlatformFileFlags {
28  PLATFORM_FILE_OPEN = 1,
29  PLATFORM_FILE_CREATE = 2,
30  PLATFORM_FILE_OPEN_ALWAYS = 4,    // May create a new file.
31  PLATFORM_FILE_CREATE_ALWAYS = 8,  // May overwrite an old file.
32  PLATFORM_FILE_READ = 16,
33  PLATFORM_FILE_WRITE = 32,
34  PLATFORM_FILE_EXCLUSIVE_READ = 64,  // EXCLUSIVE is opposite of Windows SHARE
35  PLATFORM_FILE_EXCLUSIVE_WRITE = 128,
36  PLATFORM_FILE_ASYNC = 256,
37  PLATFORM_FILE_TEMPORARY = 512,        // Used on Windows only
38  PLATFORM_FILE_HIDDEN = 1024,          // Used on Windows only
39  PLATFORM_FILE_DELETE_ON_CLOSE = 2048
40};
41
42// Creates or opens the given file. If PLATFORM_FILE_OPEN_ALWAYS is used, and
43// |created| is provided, |created| will be set to true if the file was created
44// or to false in case the file was just opened.
45PlatformFile CreatePlatformFile(const FilePath& name,
46                                int flags,
47                                bool* created);
48// Deprecated.
49PlatformFile CreatePlatformFile(const std::wstring& name,
50                                int flags,
51                                bool* created);
52
53// Closes a file handle
54bool ClosePlatformFile(PlatformFile file);
55
56}  // namespace base
57
58#endif  // BASE_PLATFORM_FILE_H_
59