Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: base/platform_file.h

Issue 14886003: Make base:ReplaceFile return an informative error. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ToT Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util_win.cc ('k') | base/platform_file_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_PLATFORM_FILE_H_ 5 #ifndef BASE_PLATFORM_FILE_H_
6 #define BASE_PLATFORM_FILE_H_ 6 #define BASE_PLATFORM_FILE_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
11 #endif 11 #endif
12 12
13 #include <string> 13 #include <string>
14 14
15 #include "base/base_export.h" 15 #include "base/base_export.h"
16 #include "base/basictypes.h" 16 #include "base/basictypes.h"
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/time.h" 18 #include "base/time.h"
19 19
20 namespace base { 20 namespace base {
21 21
22 #if defined(OS_WIN)
23 typedef HANDLE PlatformFile;
24 const PlatformFile kInvalidPlatformFileValue = INVALID_HANDLE_VALUE;
25 #elif defined(OS_POSIX)
26 typedef int PlatformFile;
27 const PlatformFile kInvalidPlatformFileValue = -1;
28 #endif
29
30 // PLATFORM_FILE_(OPEN|CREATE).* are mutually exclusive. You should specify 22 // PLATFORM_FILE_(OPEN|CREATE).* are mutually exclusive. You should specify
31 // exactly one of the five (possibly combining with other flags) when opening 23 // exactly one of the five (possibly combining with other flags) when opening
32 // or creating a file. 24 // or creating a file.
33 enum PlatformFileFlags { 25 enum PlatformFileFlags {
34 PLATFORM_FILE_OPEN = 1 << 0, // Opens a file, only if it exists. 26 PLATFORM_FILE_OPEN = 1 << 0, // Opens a file, only if it exists.
35 PLATFORM_FILE_CREATE = 1 << 1, // Creates a new file, only if it 27 PLATFORM_FILE_CREATE = 1 << 1, // Creates a new file, only if it
36 // does not already exist. 28 // does not already exist.
37 PLATFORM_FILE_OPEN_ALWAYS = 1 << 2, // May create a new file. 29 PLATFORM_FILE_OPEN_ALWAYS = 1 << 2, // May create a new file.
38 PLATFORM_FILE_CREATE_ALWAYS = 1 << 3, // May overwrite an old file. 30 PLATFORM_FILE_CREATE_ALWAYS = 1 << 3, // May overwrite an old file.
39 PLATFORM_FILE_OPEN_TRUNCATED = 1 << 4, // Opens a file and truncates it, 31 PLATFORM_FILE_OPEN_TRUNCATED = 1 << 4, // Opens a file and truncates it,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // The last modified time of a file. 104 // The last modified time of a file.
113 base::Time last_modified; 105 base::Time last_modified;
114 106
115 // The last accessed time of a file. 107 // The last accessed time of a file.
116 base::Time last_accessed; 108 base::Time last_accessed;
117 109
118 // The creation time of a file. 110 // The creation time of a file.
119 base::Time creation_time; 111 base::Time creation_time;
120 }; 112 };
121 113
114 #if defined(OS_WIN)
115 typedef HANDLE PlatformFile;
116 const PlatformFile kInvalidPlatformFileValue = INVALID_HANDLE_VALUE;
117 PlatformFileError LastErrorToPlatformFileError(DWORD saved_errno);
118 #elif defined(OS_POSIX)
119 typedef int PlatformFile;
120 const PlatformFile kInvalidPlatformFileValue = -1;
121 PlatformFileError ErrnoToPlatformFileError(int saved_errno);
122 #endif
123
122 // Creates or opens the given file. If |created| is provided, it will be set to 124 // Creates or opens the given file. If |created| is provided, it will be set to
123 // true if a new file was created [or an old one truncated to zero length to 125 // true if a new file was created [or an old one truncated to zero length to
124 // simulate a new file, which can happen with PLATFORM_FILE_CREATE_ALWAYS], and 126 // simulate a new file, which can happen with PLATFORM_FILE_CREATE_ALWAYS], and
125 // false otherwise. |error| can be NULL. 127 // false otherwise. |error| can be NULL.
126 // 128 //
127 // This function fails with 'access denied' if the |name| contains path 129 // This function fails with 'access denied' if the |name| contains path
128 // traversal ('..') components. 130 // traversal ('..') components.
129 BASE_EXPORT PlatformFile CreatePlatformFile(const FilePath& name, 131 BASE_EXPORT PlatformFile CreatePlatformFile(const FilePath& name,
130 int flags, 132 int flags,
131 bool* created, 133 bool* created,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 return temp; 240 return temp;
239 } 241 }
240 242
241 private: 243 private:
242 PlatformFile* value_; 244 PlatformFile* value_;
243 }; 245 };
244 246
245 } // namespace base 247 } // namespace base
246 248
247 #endif // BASE_PLATFORM_FILE_H_ 249 #endif // BASE_PLATFORM_FILE_H_
OLDNEW
« no previous file with comments | « base/file_util_win.cc ('k') | base/platform_file_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698