blob: 90f543e30ff77c3f9addcf2af34fc95612bb988d [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
Yi Jinbdf58942017-11-14 17:58:19 -080017#define LOG_TAG "incidentd"
18
Yi Jin99c248f2017-08-25 18:11:58 -070019#include "io_util.h"
20
21#include <unistd.h>
22
23status_t write_all(int fd, uint8_t const* buf, size_t size)
24{
25 while (size > 0) {
Yi Jin4bab3a12018-01-10 16:50:59 -080026 ssize_t amt = TEMP_FAILURE_RETRY(::write(fd, buf, size));
Yi Jin99c248f2017-08-25 18:11:58 -070027 if (amt < 0) {
28 return -errno;
29 }
30 size -= amt;
31 buf += amt;
32 }
33 return NO_ERROR;
34}
35
36Fpipe::Fpipe() {}
37
38Fpipe::~Fpipe() { close(); }
39
40bool Fpipe::close() { return !(::close(mFds[0]) || ::close(mFds[1])); }
41
42bool Fpipe::init() { return pipe(mFds) != -1; }
43
44int Fpipe::readFd() const { return mFds[0]; }
45
46int Fpipe::writeFd() const { return mFds[1]; }