blob: df934e980b58a1f66affe8f850856795bd702120 [file] [log] [blame]
Brian Carlstromdb4d5402011-08-09 12:18:28 -07001// Copyright 2009 Google Inc. All Rights Reserved.
2
3#include "file.h"
4
5namespace art {
6
7bool File::ReadFully(void* buffer, int64_t num_bytes) {
8 int64_t remaining = num_bytes;
9 char* current_buffer = reinterpret_cast<char*>(buffer);
10 while (remaining > 0) {
11 int bytes_read = Read(current_buffer, remaining);
12 if (bytes_read <= 0) {
13 return false;
14 }
15 remaining -= bytes_read; // Reduce the number of remaining bytes.
16 current_buffer += bytes_read; // Move the buffer forward.
17 }
18 return true;
19}
20
21
22bool File::WriteFully(const void* buffer, int64_t num_bytes) {
23 int64_t remaining = num_bytes;
24 const char* current_buffer = reinterpret_cast<const char*>(buffer);
25 while (remaining > 0) {
26 int bytes_read = Write(current_buffer, remaining);
27 if (bytes_read < 0) {
28 return false;
29 }
30 remaining -= bytes_read; // Reduce the number of remaining bytes.
31 current_buffer += bytes_read; // Move the buffer forward.
32 }
33 return true;
34}
35
36} // namespace art