OLD | NEW |
(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 namespace rtc { |
| 14 |
| 15 File::File(rtc::PlatformFile file) : file_(file) {} |
| 16 |
| 17 File::~File() { |
| 18 Close(); |
| 19 } |
| 20 |
| 21 size_t File::Write(const uint8_t* data, size_t length) { |
| 22 size_t total_written = 0; |
| 23 do { |
| 24 size_t written = |
| 25 WriteNoBestEffort(data + total_written, length - total_written); |
| 26 if (written == 0) |
| 27 break; |
| 28 total_written += written; |
| 29 } while (total_written < length); |
| 30 return total_written; |
| 31 } |
| 32 |
| 33 size_t File::Read(uint8_t* buffer, size_t length) { |
| 34 size_t total_read = 0; |
| 35 do { |
| 36 size_t read = ReadNoBestEffort(buffer + total_read, length - total_read); |
| 37 if (read == 0) |
| 38 break; |
| 39 total_read += read; |
| 40 } while (total_read < length); |
| 41 return total_read; |
| 42 } |
| 43 |
| 44 size_t File::WriteAt(const uint8_t* data, size_t length, size_t offset) { |
| 45 size_t total_written = 0; |
| 46 do { |
| 47 size_t written = WriteAtNoBestEffort( |
| 48 data + total_written, length - total_written, offset + total_written); |
| 49 if (written == 0) |
| 50 break; |
| 51 total_written += written; |
| 52 } while (total_written < length); |
| 53 return total_written; |
| 54 } |
| 55 |
| 56 size_t File::ReadAt(uint8_t* buffer, size_t length, size_t offset) { |
| 57 size_t total_read = 0; |
| 58 do { |
| 59 size_t read = ReadAtNoBestEffort(buffer + total_read, length - total_read, |
| 60 offset + total_read); |
| 61 if (read == 0) |
| 62 break; |
| 63 total_read += read; |
| 64 } while (total_read < length); |
| 65 return total_read; |
| 66 } |
| 67 |
| 68 } // namespace rtc |
OLD | NEW |