| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 void File::Close() { | 117 void File::Close() { |
| 113 if (file_.IsValid()) { | 118 if (file_.IsValid()) { |
| 114 base::ThreadRestrictions::AssertIOAllowed(); | 119 base::ThreadRestrictions::AssertIOAllowed(); |
| 115 file_.Close(); | 120 file_.Close(); |
| 116 } | 121 } |
| 117 } | 122 } |
| 118 | 123 |
| 119 int64 File::Seek(Whence whence, int64 offset) { | 124 int64 File::Seek(Whence whence, int64 offset) { |
| 120 base::ThreadRestrictions::AssertIOAllowed(); | 125 base::ThreadRestrictions::AssertIOAllowed(); |
| 121 DCHECK(IsValid()); | 126 DCHECK(IsValid()); |
| 122 if (offset < 0) | |
| 123 return -1; | |
| 124 | 127 |
| 125 LARGE_INTEGER distance, res; | 128 LARGE_INTEGER distance, res; |
| 126 distance.QuadPart = offset; | 129 distance.QuadPart = offset; |
| 127 DWORD move_method = static_cast<DWORD>(whence); | 130 DWORD move_method = static_cast<DWORD>(whence); |
| 128 if (!SetFilePointerEx(file_, distance, &res, move_method)) | 131 if (!SetFilePointerEx(file_, distance, &res, move_method)) |
| 129 return -1; | 132 return -1; |
| 130 return res.QuadPart; | 133 return res.QuadPart; |
| 131 } | 134 } |
| 132 | 135 |
| 133 int File::Read(int64 offset, char* data, int size) { | 136 int File::Read(int64 offset, char* data, int size) { |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 last_error); | 343 last_error); |
| 341 return FILE_ERROR_FAILED; | 344 return FILE_ERROR_FAILED; |
| 342 } | 345 } |
| 343 } | 346 } |
| 344 | 347 |
| 345 void File::SetPlatformFile(PlatformFile file) { | 348 void File::SetPlatformFile(PlatformFile file) { |
| 346 file_.Set(file); | 349 file_.Set(file); |
| 347 } | 350 } |
| 348 | 351 |
| 349 } // namespace base | 352 } // namespace base |
| OLD | NEW |