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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/base/file_win.cc
diff --git a/webrtc/base/file_win.cc b/webrtc/base/file_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7cfde6a21fe57977b0383eba562e0c5500814f05
--- /dev/null
+++ b/webrtc/base/file_win.cc
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/base/file.h"
+
+#include <io.h>
+
+#include <limits>
+
+#include "webrtc/base/checks.h"
+
+#if defined(WEBRTC_WIN)
+#include <windows.h>
+#endif
+
+namespace rtc {
+
+size_t File::WriteNoBestEffort(const uint8_t* data, size_t length) {
+ RTC_CHECK_LT(length, std::numeric_limits<DWORD>::max());
+ DWORD bytes_written;
+ if (::WriteFile(file_, data, static_cast<DWORD>(length), &bytes_written,
+ nullptr))
+ return bytes_written;
+ return 0;
+}
+
+size_t File::ReadNoBestEffort(uint8_t* buffer, size_t length) {
+ RTC_CHECK_LT(length, std::numeric_limits<DWORD>::max());
+ DWORD bytes_read;
+ if (::ReadFile(file_, buffer, static_cast<DWORD>(length), &bytes_read,
+ nullptr))
+ return bytes_read;
+ return 0;
+}
+
+size_t File::WriteAtNoBestEffort(const uint8_t* data,
+ size_t length,
+ size_t offset) {
+ RTC_CHECK_LT(length, std::numeric_limits<DWORD>::max());
+ LARGE_INTEGER offset_li;
+ offset_li.QuadPart = offset;
+
+ OVERLAPPED overlapped = {0};
+ overlapped.Offset = offset_li.LowPart;
+ overlapped.OffsetHigh = offset_li.HighPart;
+
+ DWORD bytes_written;
+ if (::WriteFile(file_, data, static_cast<DWORD>(length), &bytes_written,
+ &overlapped)) {
+ return bytes_written;
+ }
+ return 0;
+}
+
+size_t File::ReadAtNoBestEffort(uint8_t* data, size_t length, size_t offset) {
+ RTC_CHECK_LT(length, std::numeric_limits<DWORD>::max());
+ LARGE_INTEGER offset_li;
+ offset_li.QuadPart = offset;
+
+ OVERLAPPED overlapped = {0};
+ overlapped.Offset = offset_li.LowPart;
+ overlapped.OffsetHigh = offset_li.HighPart;
+
+ DWORD bytes_read;
+ if (::ReadFile(file_, data, static_cast<DWORD>(length), &bytes_read,
+ &overlapped)) {
+ return bytes_read;
+ }
+ return 0;
+}
+
+bool File::Seek(size_t offset) {
+ LARGE_INTEGER distance;
+ distance.QuadPart = offset;
+ return SetFilePointerEx(file_, distance, nullptr, FILE_BEGIN) != 0;
+}
+
+bool File::Close() {
+ if (file_ == rtc::kInvalidPlatformFileValue)
+ return false;
+ bool ret = CloseHandle(file_) != 0;
+ file_ = rtc::kInvalidPlatformFileValue;
+ return ret;
+}
+
+} // namespace rtc

Powered by Google App Engine
This is Rietveld 408576698