blob: 310876b1cc36426a3c47277ad14af710fdbace42 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian Carlstromdb4d5402011-08-09 12:18:28 -070016
17#include "file.h"
18
19namespace art {
20
21bool File::ReadFully(void* buffer, int64_t num_bytes) {
22 int64_t remaining = num_bytes;
23 char* current_buffer = reinterpret_cast<char*>(buffer);
24 while (remaining > 0) {
25 int bytes_read = Read(current_buffer, remaining);
26 if (bytes_read <= 0) {
27 return false;
28 }
29 remaining -= bytes_read; // Reduce the number of remaining bytes.
30 current_buffer += bytes_read; // Move the buffer forward.
31 }
32 return true;
33}
34
35
36bool File::WriteFully(const void* buffer, int64_t num_bytes) {
37 int64_t remaining = num_bytes;
38 const char* current_buffer = reinterpret_cast<const char*>(buffer);
39 while (remaining > 0) {
40 int bytes_read = Write(current_buffer, remaining);
41 if (bytes_read < 0) {
42 return false;
43 }
44 remaining -= bytes_read; // Reduce the number of remaining bytes.
45 current_buffer += bytes_read; // Move the buffer forward.
46 }
47 return true;
48}
49
50} // namespace art