OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // false otherwise. |error_code| can be NULL. | 110 // false otherwise. |error_code| can be NULL. |
111 BASE_EXPORT PlatformFile CreatePlatformFile(const FilePath& name, | 111 BASE_EXPORT PlatformFile CreatePlatformFile(const FilePath& name, |
112 int flags, | 112 int flags, |
113 bool* created, | 113 bool* created, |
114 PlatformFileError* error_code); | 114 PlatformFileError* error_code); |
115 | 115 |
116 // Closes a file handle. Returns |true| on success and |false| otherwise. | 116 // Closes a file handle. Returns |true| on success and |false| otherwise. |
117 BASE_EXPORT bool ClosePlatformFile(PlatformFile file); | 117 BASE_EXPORT bool ClosePlatformFile(PlatformFile file); |
118 | 118 |
119 // Reads the given number of bytes (or until EOF is reached) starting with the | 119 // Reads the given number of bytes (or until EOF is reached) starting with the |
120 // given offset. Returns the number of bytes read, or -1 on error. | 120 // given offset. Returns the number of bytes read, or -1 on error. Note that |
| 121 // this function makes a best effort to read all data on all platforms, so it is |
| 122 // not intended for stream oriented files but instead for cases when the normal |
| 123 // expectation is that actually |size| bytes are read unless there is an error. |
121 BASE_EXPORT int ReadPlatformFile(PlatformFile file, int64 offset, | 124 BASE_EXPORT int ReadPlatformFile(PlatformFile file, int64 offset, |
122 char* data, int size); | 125 char* data, int size); |
123 | 126 |
| 127 // Reads the given number of bytes (or until EOF is reached) starting with the |
| 128 // given offset, but does not make any effort to read all data on all platforms. |
| 129 // Returns the number of bytes read, or -1 on error. |
| 130 BASE_EXPORT int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, |
| 131 char* data, int size); |
| 132 |
124 // Writes the given buffer into the file at the given offset, overwritting any | 133 // Writes the given buffer into the file at the given offset, overwritting any |
125 // data that was previously there. Returns the number of bytes written, or -1 | 134 // data that was previously there. Returns the number of bytes written, or -1 |
126 // on error. Note that this function makes a best effort to write all data on | 135 // on error. Note that this function makes a best effort to write all data on |
127 // all platforms. | 136 // all platforms. |
128 BASE_EXPORT int WritePlatformFile(PlatformFile file, int64 offset, | 137 BASE_EXPORT int WritePlatformFile(PlatformFile file, int64 offset, |
129 const char* data, int size); | 138 const char* data, int size); |
130 | 139 |
131 // Truncates the given file to the given length. If |length| is greater than | 140 // Truncates the given file to the given length. If |length| is greater than |
132 // the current size of the file, the file is extended with zeros. If the file | 141 // the current size of the file, the file is extended with zeros. If the file |
133 // doesn't exist, |false| is returned. | 142 // doesn't exist, |false| is returned. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 return temp; | 187 return temp; |
179 } | 188 } |
180 | 189 |
181 private: | 190 private: |
182 PlatformFile* value_; | 191 PlatformFile* value_; |
183 }; | 192 }; |
184 | 193 |
185 } // namespace base | 194 } // namespace base |
186 | 195 |
187 #endif // BASE_PLATFORM_FILE_H_ | 196 #endif // BASE_PLATFORM_FILE_H_ |
OLD | NEW |