// Copyright (c) 2007 The NetBSD Foundation, Inc.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions5// are met:6// 1. Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// 2. Redistributions in binary form must reproduce the above copyright9// notice, this list of conditions and the following disclaimer in the10// documentation and/or other materials provided with the distribution.11//12// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND13// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,14// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF15// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE19// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS20// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER21// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN23// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2425#include "atf-c++/utils.hpp"2627extern "C" {28#include "atf-c/utils.h"29}3031#include <cstdlib>32#include <iostream>3334void35atf::utils::cat_file(const std::string& path, const std::string& prefix)36{37atf_utils_cat_file(path.c_str(), prefix.c_str());38}3940void41atf::utils::copy_file(const std::string& source, const std::string& destination)42{43atf_utils_copy_file(source.c_str(), destination.c_str());44}4546bool47atf::utils::compare_file(const std::string& path, const std::string& contents)48{49return atf_utils_compare_file(path.c_str(), contents.c_str());50}5152void53atf::utils::create_file(const std::string& path, const std::string& contents)54{55atf_utils_create_file(path.c_str(), "%s", contents.c_str());56}5758bool59atf::utils::file_exists(const std::string& path)60{61return atf_utils_file_exists(path.c_str());62}6364pid_t65atf::utils::fork(void)66{67std::cout.flush();68std::cerr.flush();69return atf_utils_fork();70}7172void73atf::utils::reset_resultsfile(void)74{7576atf_utils_reset_resultsfile();77}7879bool80atf::utils::grep_file(const std::string& regex, const std::string& path)81{82return atf_utils_grep_file("%s", path.c_str(), regex.c_str());83}8485bool86atf::utils::grep_string(const std::string& regex, const std::string& str)87{88return atf_utils_grep_string("%s", str.c_str(), regex.c_str());89}9091void92atf::utils::redirect(const int fd, const std::string& path)93{94if (fd == STDOUT_FILENO)95std::cout.flush();96else if (fd == STDERR_FILENO)97std::cerr.flush();98atf_utils_redirect(fd, path.c_str());99}100101void102atf::utils::wait(const pid_t pid, const int exitstatus,103const std::string& expout, const std::string& experr)104{105atf_utils_wait(pid, exitstatus, expout.c_str(), experr.c_str());106}107108109