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 #include "base/files/file.h" | 5 #include "base/files/file.h" |
6 | 6 |
7 #include <io.h> | 7 #include <io.h> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 | 15 |
| 16 // Make sure our Whence mappings match the system headers. |
| 17 COMPILE_ASSERT(File::FROM_BEGIN == FILE_BEGIN && |
| 18 File::FROM_CURRENT == FILE_CURRENT && |
| 19 File::FROM_END == FILE_END, whence_matches_system); |
| 20 |
16 void File::InitializeUnsafe(const FilePath& name, uint32 flags) { | 21 void File::InitializeUnsafe(const FilePath& name, uint32 flags) { |
17 base::ThreadRestrictions::AssertIOAllowed(); | 22 base::ThreadRestrictions::AssertIOAllowed(); |
18 DCHECK(!IsValid()); | 23 DCHECK(!IsValid()); |
19 | 24 |
20 DWORD disposition = 0; | 25 DWORD disposition = 0; |
21 | 26 |
22 if (flags & FLAG_OPEN) | 27 if (flags & FLAG_OPEN) |
23 disposition = OPEN_EXISTING; | 28 disposition = OPEN_EXISTING; |
24 | 29 |
25 if (flags & FLAG_CREATE) { | 30 if (flags & FLAG_CREATE) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 void File::Close() { | 116 void File::Close() { |
112 if (file_.IsValid()) { | 117 if (file_.IsValid()) { |
113 base::ThreadRestrictions::AssertIOAllowed(); | 118 base::ThreadRestrictions::AssertIOAllowed(); |
114 file_.Close(); | 119 file_.Close(); |
115 } | 120 } |
116 } | 121 } |
117 | 122 |
118 int64 File::Seek(Whence whence, int64 offset) { | 123 int64 File::Seek(Whence whence, int64 offset) { |
119 base::ThreadRestrictions::AssertIOAllowed(); | 124 base::ThreadRestrictions::AssertIOAllowed(); |
120 DCHECK(IsValid()); | 125 DCHECK(IsValid()); |
121 if (offset < 0) | |
122 return -1; | |
123 | 126 |
124 LARGE_INTEGER distance, res; | 127 LARGE_INTEGER distance, res; |
125 distance.QuadPart = offset; | 128 distance.QuadPart = offset; |
126 DWORD move_method = static_cast<DWORD>(whence); | 129 DWORD move_method = static_cast<DWORD>(whence); |
127 if (!SetFilePointerEx(file_, distance, &res, move_method)) | 130 if (!SetFilePointerEx(file_, distance, &res, move_method)) |
128 return -1; | 131 return -1; |
129 return res.QuadPart; | 132 return res.QuadPart; |
130 } | 133 } |
131 | 134 |
132 int File::Read(int64 offset, char* data, int size) { | 135 int File::Read(int64 offset, char* data, int size) { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 last_error); | 342 last_error); |
340 return FILE_ERROR_FAILED; | 343 return FILE_ERROR_FAILED; |
341 } | 344 } |
342 } | 345 } |
343 | 346 |
344 void File::SetPlatformFile(PlatformFile file) { | 347 void File::SetPlatformFile(PlatformFile file) { |
345 file_.Set(file); | 348 file_.Set(file); |
346 } | 349 } |
347 | 350 |
348 } // namespace base | 351 } // namespace base |
OLD | NEW |