1 // Copyright 2018 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <qemu_pipe_bp.h>
16
qemu_pipe_read_fully(QEMU_PIPE_HANDLE pipe,void * buffer,int size)17 int qemu_pipe_read_fully(QEMU_PIPE_HANDLE pipe, void* buffer, int size) {
18 char* p = (char*)buffer;
19
20 while (size > 0) {
21 int n = QEMU_PIPE_RETRY(qemu_pipe_read(pipe, p, size));
22 if (n < 0) return n;
23
24 p += n;
25 size -= n;
26 }
27
28 return 0;
29 }
30
qemu_pipe_write_fully(QEMU_PIPE_HANDLE pipe,const void * buffer,int size)31 int qemu_pipe_write_fully(QEMU_PIPE_HANDLE pipe, const void* buffer, int size) {
32 const char* p = (const char*)buffer;
33
34 while (size > 0) {
35 int n = QEMU_PIPE_RETRY(qemu_pipe_write(pipe, p, size));
36 if (n < 0) return n;
37
38 p += n;
39 size -= n;
40 }
41
42 return 0;
43 }
44