Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: webrtc/base/file_win.cc

Issue 2214763002: Initial version of new file wrapper (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Test random access better Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/base/file.h"
12
13 #include <io.h>
14
15 #include <limits>
16
17 #include "webrtc/base/checks.h"
18
19 #if defined(WEBRTC_WIN)
20 #include <windows.h>
21 #endif
22
23 namespace rtc {
24
25 size_t File::WriteNoBestEffort(const uint8_t* data, size_t length) {
26 RTC_CHECK_LT(length, std::numeric_limits<DWORD>::max());
27 DWORD bytes_written;
28 if (::WriteFile(file_, data, static_cast<DWORD>(length), &bytes_written,
29 nullptr))
30 return bytes_written;
31 return 0;
32 }
33
34 size_t File::ReadNoBestEffort(uint8_t* buffer, size_t length) {
35 RTC_CHECK_LT(length, std::numeric_limits<DWORD>::max());
36 DWORD bytes_read;
37 if (::ReadFile(file_, buffer, static_cast<DWORD>(length), &bytes_read,
38 nullptr))
39 return bytes_read;
40 return 0;
41 }
42
43 size_t File::WriteAtNoBestEffort(const uint8_t* data,
44 size_t length,
45 size_t offset) {
46 RTC_CHECK_LT(length, std::numeric_limits<DWORD>::max());
47 LARGE_INTEGER offset_li;
48 offset_li.QuadPart = offset;
49
50 OVERLAPPED overlapped = {0};
51 overlapped.Offset = offset_li.LowPart;
52 overlapped.OffsetHigh = offset_li.HighPart;
53
54 DWORD bytes_written;
55 if (::WriteFile(file_, data, static_cast<DWORD>(length), &bytes_written,
56 &overlapped)) {
57 return bytes_written;
58 }
59 return 0;
60 }
61
62 size_t File::ReadAtNoBestEffort(uint8_t* data, size_t length, size_t offset) {
63 RTC_CHECK_LT(length, std::numeric_limits<DWORD>::max());
64 LARGE_INTEGER offset_li;
65 offset_li.QuadPart = offset;
66
67 OVERLAPPED overlapped = {0};
68 overlapped.Offset = offset_li.LowPart;
69 overlapped.OffsetHigh = offset_li.HighPart;
70
71 DWORD bytes_read;
72 if (::ReadFile(file_, data, static_cast<DWORD>(length), &bytes_read,
73 &overlapped)) {
74 return bytes_read;
75 }
76 return 0;
77 }
78
79 bool File::Seek(size_t offset) {
80 LARGE_INTEGER distance;
81 distance.QuadPart = offset;
82 return SetFilePointerEx(file_, distance, nullptr, FILE_BEGIN) != 0;
83 }
84
85 bool File::Close() {
86 if (file_ == rtc::kInvalidPlatformFileValue)
87 return false;
88 bool ret = CloseHandle(file_) != 0;
89 file_ = rtc::kInvalidPlatformFileValue;
90 return ret;
91 }
92
93 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698