//
// Automated Testing Framework (atf)
//
// Copyright (c) 2007 The NetBSD Foundation, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
//
// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
extern "C" {
#include <fcntl.h>
#include <poll.h>
#include <signal.h>
#include <unistd.h>
}
#include <cerrno>
#include <cstring>
extern "C" {
}
#include "../atf-c++/detail/auto_array.hpp"
#include "../atf-c++/detail/exceptions.hpp"
#include "../atf-c++/detail/sanity.hpp"
#include "io.hpp"
// ------------------------------------------------------------------------
// The "file_handle" class.
// ------------------------------------------------------------------------
{
}
m_handle(h)
{
}
{
}
{
if (is_valid())
close();
}
{
return *this;
}
bool
const
{
return m_handle != invalid_value();
}
void
{
m_handle = invalid_value();
}
{
handle_type h = m_handle;
m_handle = invalid_value();
return h;
}
const
{
return m_handle;
}
void
{
if (m_handle == h)
return;
"dup2(2) failed", errno);
::close(h);
"close(2) failed", errno);
}
m_handle = h;
}
{
return -1;
}
// ------------------------------------------------------------------------
// The "systembuf" class.
// ------------------------------------------------------------------------
m_handle(h),
{
try {
m_read_buf = new char[bufsize];
m_write_buf = new char[bufsize];
} catch (...) {
if (m_read_buf != NULL)
delete [] m_read_buf;
if (m_write_buf != NULL)
delete [] m_write_buf;
throw;
}
}
{
delete [] m_read_buf;
delete [] m_write_buf;
}
{
bool ok;
if (!ok)
return traits_type::eof();
else {
}
}
{
if (sync() == -1)
return traits_type::eof();
pbump(1);
}
return traits_type::not_eof(c);
}
int
{
bool ok;
if (ok)
return ok ? 0 : -1;
}
// ------------------------------------------------------------------------
// The "pistream" class.
// ------------------------------------------------------------------------
{
rdbuf(&m_systembuf);
}
// ------------------------------------------------------------------------
// The "muxer" class.
// ------------------------------------------------------------------------
static int
{
if (ret == -1) {
ret = 0;
else
errno);
}
return ret;
}
static size_t
const bool report_errors)
{
int ret;
if (ret == -1) {
if (report_errors)
errno);
else
ret = 0;
}
}
{
}
{
}
const bool report_errors)
{
size_t line_start = 0;
if (buffer[i] == '\n') {
line_start = i + 1;
} else if (buffer[i] == '\r') {
// Do nothing.
} else {
}
}
return nbytes;
}
void
{
}
int ret;
continue;
// Any data still available at this point will be processed by
// a call to the flush method.
nactive--;
POLLPRI)) {
}
}
}
}
void
{
line_callback(i, m_buffers[i]);
}
}