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 <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 FILE* FdopenPlatformFile(PlatformFile file, const char* mode) { | |
17 if (file == kInvalidPlatformFileValue) | |
18 return NULL; | |
19 int fd = _open_osfhandle(reinterpret_cast<intptr_t>(file), 0); | |
20 if (fd < 0) | |
21 return NULL; | |
22 return _fdopen(fd, mode); | |
23 } | |
24 | |
25 bool ClosePlatformFile(PlatformFile file) { | 16 bool ClosePlatformFile(PlatformFile file) { |
26 base::ThreadRestrictions::AssertIOAllowed(); | 17 base::ThreadRestrictions::AssertIOAllowed(); |
27 return (CloseHandle(file) != 0); | 18 return (CloseHandle(file) != 0); |
28 } | 19 } |
29 | 20 |
30 int64 SeekPlatformFile(PlatformFile file, | 21 int64 SeekPlatformFile(PlatformFile file, |
31 PlatformFileWhence whence, | 22 PlatformFileWhence whence, |
32 int64 offset) { | 23 int64 offset) { |
33 base::ThreadRestrictions::AssertIOAllowed(); | 24 base::ThreadRestrictions::AssertIOAllowed(); |
34 if (file == kInvalidPlatformFileValue || offset < 0) | 25 if (file == kInvalidPlatformFileValue || offset < 0) |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 case ERROR_DISK_CORRUPT: | 217 case ERROR_DISK_CORRUPT: |
227 return PLATFORM_FILE_ERROR_IO; | 218 return PLATFORM_FILE_ERROR_IO; |
228 default: | 219 default: |
229 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Windows", | 220 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Windows", |
230 last_error); | 221 last_error); |
231 return PLATFORM_FILE_ERROR_FAILED; | 222 return PLATFORM_FILE_ERROR_FAILED; |
232 } | 223 } |
233 } | 224 } |
234 | 225 |
235 } // namespace base | 226 } // namespace base |
OLD | NEW |