blob: f043d367d9820e9654ff67b3bd3d587bc6f731c6 [file] [log] [blame]
Yi Jin99c248f2017-08-25 18:11:58 -07001/*
2 * Copyright (C) 2017 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 */
16
17#include "io_util.h"
18
19#include <unistd.h>
20
21status_t write_all(int fd, uint8_t const* buf, size_t size)
22{
23 while (size > 0) {
24 ssize_t amt = ::write(fd, buf, size);
25 if (amt < 0) {
26 return -errno;
27 }
28 size -= amt;
29 buf += amt;
30 }
31 return NO_ERROR;
32}
33
34Fpipe::Fpipe() {}
35
36Fpipe::~Fpipe() { close(); }
37
38bool Fpipe::close() { return !(::close(mFds[0]) || ::close(mFds[1])); }
39
40bool Fpipe::init() { return pipe(mFds) != -1; }
41
42int Fpipe::readFd() const { return mFds[0]; }
43
44int Fpipe::writeFd() const { return mFds[1]; }