blob: 279c5d2cfbf8c5905de63774099d69aaca9af079 [file] [log] [blame]
// Copyright 2016 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/lib/files/file_descriptor.h"
#include "src/lib/files/eintr_wrapper.h"
#include "src/lib/fxl/logging.h"
namespace fxl {
bool WriteFileDescriptor(int fd, const char* data, ssize_t size) {
ssize_t total = 0;
for (ssize_t partial = 0; total < size; total += partial) {
partial = HANDLE_EINTR(write(fd, data + total, size - total));
if (partial < 0)
return false;
}
return true;
}
ssize_t ReadFileDescriptor(int fd, char* data, ssize_t max_size) {
ssize_t total = 0;
for (ssize_t partial = 0; total < max_size; total += partial) {
partial = HANDLE_EINTR(read(fd, data + total, max_size - total));
if (partial <= 0)
return total ? total : partial;
}
return total;
}
} // namespace fxl