OLD | NEW |
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 // PLATFORM_FILE_(OPEN|CREATE).* are mutually exclusive. You should specify | 22 // PLATFORM_FILE_(OPEN|CREATE).* are mutually exclusive. You should specify |
23 // 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 |
24 // or creating a file. | 24 // or creating a file. |
| 25 // PLATFORM_FILE_(WRITE|APPEND) are mutually exclusive. This is so that APPEND |
| 26 // behavior will be consistent with O_APPEND on POSIX. |
25 enum PlatformFileFlags { | 27 enum PlatformFileFlags { |
26 PLATFORM_FILE_OPEN = 1 << 0, // Opens a file, only if it exists. | 28 PLATFORM_FILE_OPEN = 1 << 0, // Opens a file, only if it exists. |
27 PLATFORM_FILE_CREATE = 1 << 1, // Creates a new file, only if it | 29 PLATFORM_FILE_CREATE = 1 << 1, // Creates a new file, only if it |
28 // does not already exist. | 30 // does not already exist. |
29 PLATFORM_FILE_OPEN_ALWAYS = 1 << 2, // May create a new file. | 31 PLATFORM_FILE_OPEN_ALWAYS = 1 << 2, // May create a new file. |
30 PLATFORM_FILE_CREATE_ALWAYS = 1 << 3, // May overwrite an old file. | 32 PLATFORM_FILE_CREATE_ALWAYS = 1 << 3, // May overwrite an old file. |
31 PLATFORM_FILE_OPEN_TRUNCATED = 1 << 4, // Opens a file and truncates it, | 33 PLATFORM_FILE_OPEN_TRUNCATED = 1 << 4, // Opens a file and truncates it, |
32 // only if it exists. | 34 // only if it exists. |
33 PLATFORM_FILE_READ = 1 << 5, | 35 PLATFORM_FILE_READ = 1 << 5, |
34 PLATFORM_FILE_WRITE = 1 << 6, | 36 PLATFORM_FILE_WRITE = 1 << 6, |
35 PLATFORM_FILE_EXCLUSIVE_READ = 1 << 7, // EXCLUSIVE is opposite of Windows | 37 PLATFORM_FILE_APPEND = 1 << 7, |
| 38 PLATFORM_FILE_EXCLUSIVE_READ = 1 << 8, // EXCLUSIVE is opposite of Windows |
36 // SHARE | 39 // SHARE |
37 PLATFORM_FILE_EXCLUSIVE_WRITE = 1 << 8, | 40 PLATFORM_FILE_EXCLUSIVE_WRITE = 1 << 9, |
38 PLATFORM_FILE_ASYNC = 1 << 9, | 41 PLATFORM_FILE_ASYNC = 1 << 10, |
39 PLATFORM_FILE_TEMPORARY = 1 << 10, // Used on Windows only | 42 PLATFORM_FILE_TEMPORARY = 1 << 11, // Used on Windows only |
40 PLATFORM_FILE_HIDDEN = 1 << 11, // Used on Windows only | 43 PLATFORM_FILE_HIDDEN = 1 << 12, // Used on Windows only |
41 PLATFORM_FILE_DELETE_ON_CLOSE = 1 << 12, | 44 PLATFORM_FILE_DELETE_ON_CLOSE = 1 << 13, |
42 | 45 |
43 PLATFORM_FILE_WRITE_ATTRIBUTES = 1 << 13, // Used on Windows only | 46 PLATFORM_FILE_WRITE_ATTRIBUTES = 1 << 14, // Used on Windows only |
44 PLATFORM_FILE_ENUMERATE = 1 << 14, // May enumerate directory | 47 PLATFORM_FILE_ENUMERATE = 1 << 15, // May enumerate directory |
45 | 48 |
46 PLATFORM_FILE_SHARE_DELETE = 1 << 15, // Used on Windows only | 49 PLATFORM_FILE_SHARE_DELETE = 1 << 16, // Used on Windows only |
47 | 50 |
48 PLATFORM_FILE_TERMINAL_DEVICE = 1 << 16, // Serial port flags | 51 PLATFORM_FILE_TERMINAL_DEVICE = 1 << 17, // Serial port flags |
49 PLATFORM_FILE_BACKUP_SEMANTICS = 1 << 17, // Used on Windows only | 52 PLATFORM_FILE_BACKUP_SEMANTICS = 1 << 18, // Used on Windows only |
50 | 53 |
51 PLATFORM_FILE_EXECUTE = 1 << 18, // Used on Windows only | 54 PLATFORM_FILE_EXECUTE = 1 << 19, // Used on Windows only |
52 }; | 55 }; |
53 | 56 |
54 // PLATFORM_FILE_ERROR_ACCESS_DENIED is returned when a call fails because of | 57 // PLATFORM_FILE_ERROR_ACCESS_DENIED is returned when a call fails because of |
55 // a filesystem restriction. PLATFORM_FILE_ERROR_SECURITY is returned when a | 58 // a filesystem restriction. PLATFORM_FILE_ERROR_SECURITY is returned when a |
56 // browser policy doesn't allow the operation to be executed. | 59 // browser policy doesn't allow the operation to be executed. |
57 enum PlatformFileError { | 60 enum PlatformFileError { |
58 PLATFORM_FILE_OK = 0, | 61 PLATFORM_FILE_OK = 0, |
59 PLATFORM_FILE_ERROR_FAILED = -1, | 62 PLATFORM_FILE_ERROR_FAILED = -1, |
60 PLATFORM_FILE_ERROR_IN_USE = -2, | 63 PLATFORM_FILE_ERROR_IN_USE = -2, |
61 PLATFORM_FILE_ERROR_EXISTS = -3, | 64 PLATFORM_FILE_ERROR_EXISTS = -3, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 char* data, int size); | 174 char* data, int size); |
172 | 175 |
173 // Same as above but without seek. | 176 // Same as above but without seek. |
174 BASE_EXPORT int ReadPlatformFileCurPosNoBestEffort(PlatformFile file, | 177 BASE_EXPORT int ReadPlatformFileCurPosNoBestEffort(PlatformFile file, |
175 char* data, int size); | 178 char* data, int size); |
176 | 179 |
177 // Writes the given buffer into the file at the given offset, overwritting any | 180 // Writes the given buffer into the file at the given offset, overwritting any |
178 // data that was previously there. Returns the number of bytes written, or -1 | 181 // data that was previously there. Returns the number of bytes written, or -1 |
179 // on error. Note that this function makes a best effort to write all data on | 182 // on error. Note that this function makes a best effort to write all data on |
180 // all platforms. | 183 // all platforms. |
| 184 // Ignores the offset and writes to the end of the file if the file was opened |
| 185 // with PLATFORM_FILE_APPEND. |
181 BASE_EXPORT int WritePlatformFile(PlatformFile file, int64 offset, | 186 BASE_EXPORT int WritePlatformFile(PlatformFile file, int64 offset, |
182 const char* data, int size); | 187 const char* data, int size); |
183 | 188 |
184 // Save as above but without seek. | 189 // Save as above but without seek. |
185 BASE_EXPORT int WritePlatformFileAtCurrentPos(PlatformFile file, | 190 BASE_EXPORT int WritePlatformFileAtCurrentPos(PlatformFile file, |
186 const char* data, int size); | 191 const char* data, int size); |
187 | 192 |
188 // Save as above but does not make any effort to write all data on all | 193 // Save as above but does not make any effort to write all data on all |
189 // platforms. Returns the number of bytes written, or -1 on error. | 194 // platforms. Returns the number of bytes written, or -1 on error. |
190 BASE_EXPORT int WritePlatformFileCurPosNoBestEffort(PlatformFile file, | 195 BASE_EXPORT int WritePlatformFileCurPosNoBestEffort(PlatformFile file, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 return temp; | 245 return temp; |
241 } | 246 } |
242 | 247 |
243 private: | 248 private: |
244 PlatformFile* value_; | 249 PlatformFile* value_; |
245 }; | 250 }; |
246 | 251 |
247 } // namespace base | 252 } // namespace base |
248 | 253 |
249 #endif // BASE_PLATFORM_FILE_H_ | 254 #endif // BASE_PLATFORM_FILE_H_ |
OLD | NEW |