| 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/platform_file.h" | 5 #include "base/platform_file.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 | 10 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 108 } |
| 109 | 109 |
| 110 return file; | 110 return file; |
| 111 } | 111 } |
| 112 | 112 |
| 113 bool ClosePlatformFile(PlatformFile file) { | 113 bool ClosePlatformFile(PlatformFile file) { |
| 114 base::ThreadRestrictions::AssertIOAllowed(); | 114 base::ThreadRestrictions::AssertIOAllowed(); |
| 115 return (CloseHandle(file) != 0); | 115 return (CloseHandle(file) != 0); |
| 116 } | 116 } |
| 117 | 117 |
| 118 int64 SeekPlatformFile(PlatformFile file, |
| 119 PlatformFileWhence whence, |
| 120 int64 offset) { |
| 121 base::ThreadRestrictions::AssertIOAllowed(); |
| 122 if (file < 0 || offset < 0) |
| 123 return -1; |
| 124 |
| 125 LARGE_INTEGER distance, res; |
| 126 distance.QuadPart = offset; |
| 127 DWORD move_method = static_cast<DWORD>(whence); |
| 128 if (!SetFilePointerEx(file, distance, &res, move_method)) |
| 129 return -1; |
| 130 return res.QuadPart; |
| 131 } |
| 132 |
| 118 int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) { | 133 int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) { |
| 119 base::ThreadRestrictions::AssertIOAllowed(); | 134 base::ThreadRestrictions::AssertIOAllowed(); |
| 120 if (file == kInvalidPlatformFileValue) | 135 if (file == kInvalidPlatformFileValue) |
| 121 return -1; | 136 return -1; |
| 122 | 137 |
| 123 LARGE_INTEGER offset_li; | 138 LARGE_INTEGER offset_li; |
| 124 offset_li.QuadPart = offset; | 139 offset_li.QuadPart = offset; |
| 125 | 140 |
| 126 OVERLAPPED overlapped = {0}; | 141 OVERLAPPED overlapped = {0}; |
| 127 overlapped.Offset = offset_li.LowPart; | 142 overlapped.Offset = offset_li.LowPart; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 138 | 153 |
| 139 int ReadPlatformFileAtCurrentPos(PlatformFile file, char* data, int size) { | 154 int ReadPlatformFileAtCurrentPos(PlatformFile file, char* data, int size) { |
| 140 return ReadPlatformFile(file, 0, data, size); | 155 return ReadPlatformFile(file, 0, data, size); |
| 141 } | 156 } |
| 142 | 157 |
| 143 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, char* data, | 158 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, char* data, |
| 144 int size) { | 159 int size) { |
| 145 return ReadPlatformFile(file, offset, data, size); | 160 return ReadPlatformFile(file, offset, data, size); |
| 146 } | 161 } |
| 147 | 162 |
| 163 int ReadPlatformFileCurPosNoBestEffort(PlatformFile file, |
| 164 char* data, int size) { |
| 165 return ReadPlatformFile(file, 0, data, size); |
| 166 } |
| 167 |
| 148 int WritePlatformFile(PlatformFile file, int64 offset, | 168 int WritePlatformFile(PlatformFile file, int64 offset, |
| 149 const char* data, int size) { | 169 const char* data, int size) { |
| 150 base::ThreadRestrictions::AssertIOAllowed(); | 170 base::ThreadRestrictions::AssertIOAllowed(); |
| 151 if (file == kInvalidPlatformFileValue) | 171 if (file == kInvalidPlatformFileValue) |
| 152 return -1; | 172 return -1; |
| 153 | 173 |
| 154 LARGE_INTEGER offset_li; | 174 LARGE_INTEGER offset_li; |
| 155 offset_li.QuadPart = offset; | 175 offset_li.QuadPart = offset; |
| 156 | 176 |
| 157 OVERLAPPED overlapped = {0}; | 177 OVERLAPPED overlapped = {0}; |
| 158 overlapped.Offset = offset_li.LowPart; | 178 overlapped.Offset = offset_li.LowPart; |
| 159 overlapped.OffsetHigh = offset_li.HighPart; | 179 overlapped.OffsetHigh = offset_li.HighPart; |
| 160 | 180 |
| 161 DWORD bytes_written; | 181 DWORD bytes_written; |
| 162 if (::WriteFile(file, data, size, &bytes_written, &overlapped) != 0) | 182 if (::WriteFile(file, data, size, &bytes_written, &overlapped) != 0) |
| 163 return bytes_written; | 183 return bytes_written; |
| 164 | 184 |
| 165 return -1; | 185 return -1; |
| 166 } | 186 } |
| 167 | 187 |
| 168 int WritePlatformFileAtCurrentPos(PlatformFile file, const char* data, | 188 int WritePlatformFileAtCurrentPos(PlatformFile file, const char* data, |
| 169 int size) { | 189 int size) { |
| 170 return WritePlatformFile(file, 0, data, size); | 190 return WritePlatformFile(file, 0, data, size); |
| 171 } | 191 } |
| 172 | 192 |
| 193 int WritePlatformFileCurPosNoBestEffort(PlatformFile file, |
| 194 const char* data, int size) { |
| 195 return WritePlatformFile(file, 0, data, size); |
| 196 } |
| 197 |
| 173 bool TruncatePlatformFile(PlatformFile file, int64 length) { | 198 bool TruncatePlatformFile(PlatformFile file, int64 length) { |
| 174 base::ThreadRestrictions::AssertIOAllowed(); | 199 base::ThreadRestrictions::AssertIOAllowed(); |
| 175 if (file == kInvalidPlatformFileValue) | 200 if (file == kInvalidPlatformFileValue) |
| 176 return false; | 201 return false; |
| 177 | 202 |
| 178 // Get the current file pointer. | 203 // Get the current file pointer. |
| 179 LARGE_INTEGER file_pointer; | 204 LARGE_INTEGER file_pointer; |
| 180 LARGE_INTEGER zero; | 205 LARGE_INTEGER zero; |
| 181 zero.QuadPart = 0; | 206 zero.QuadPart = 0; |
| 182 if (::SetFilePointerEx(file, zero, &file_pointer, FILE_CURRENT) == 0) | 207 if (::SetFilePointerEx(file, zero, &file_pointer, FILE_CURRENT) == 0) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 info->is_directory = | 254 info->is_directory = |
| 230 (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | 255 (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
| 231 info->is_symbolic_link = false; // Windows doesn't have symbolic links. | 256 info->is_symbolic_link = false; // Windows doesn't have symbolic links. |
| 232 info->last_modified = base::Time::FromFileTime(file_info.ftLastWriteTime); | 257 info->last_modified = base::Time::FromFileTime(file_info.ftLastWriteTime); |
| 233 info->last_accessed = base::Time::FromFileTime(file_info.ftLastAccessTime); | 258 info->last_accessed = base::Time::FromFileTime(file_info.ftLastAccessTime); |
| 234 info->creation_time = base::Time::FromFileTime(file_info.ftCreationTime); | 259 info->creation_time = base::Time::FromFileTime(file_info.ftCreationTime); |
| 235 return true; | 260 return true; |
| 236 } | 261 } |
| 237 | 262 |
| 238 } // namespace base | 263 } // namespace base |
| OLD | NEW |