1258191Sjmmv// Copyright (c) 2007 The NetBSD Foundation, Inc.
2258191Sjmmv// All rights reserved.
3258191Sjmmv//
4258191Sjmmv// Redistribution and use in source and binary forms, with or without
5258191Sjmmv// modification, are permitted provided that the following conditions
6258191Sjmmv// are met:
7258191Sjmmv// 1. Redistributions of source code must retain the above copyright
8258191Sjmmv//    notice, this list of conditions and the following disclaimer.
9258191Sjmmv// 2. Redistributions in binary form must reproduce the above copyright
10258191Sjmmv//    notice, this list of conditions and the following disclaimer in the
11258191Sjmmv//    documentation and/or other materials provided with the distribution.
12258191Sjmmv//
13258191Sjmmv// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14258191Sjmmv// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15258191Sjmmv// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16258191Sjmmv// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17258191Sjmmv// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18258191Sjmmv// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19258191Sjmmv// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20258191Sjmmv// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21258191Sjmmv// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22258191Sjmmv// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23258191Sjmmv// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24258191Sjmmv// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25258191Sjmmv
26275988Sngie#include "atf-c++/utils.hpp"
27275988Sngie
28258191Sjmmvextern "C" {
29258191Sjmmv#include "atf-c/utils.h"
30258191Sjmmv}
31258191Sjmmv
32258191Sjmmv#include <cstdlib>
33258191Sjmmv#include <iostream>
34258191Sjmmv
35258191Sjmmvvoid
36258191Sjmmvatf::utils::cat_file(const std::string& path, const std::string& prefix)
37258191Sjmmv{
38258191Sjmmv    atf_utils_cat_file(path.c_str(), prefix.c_str());
39258191Sjmmv}
40258191Sjmmv
41258191Sjmmvvoid
42258191Sjmmvatf::utils::copy_file(const std::string& source, const std::string& destination)
43258191Sjmmv{
44258191Sjmmv    atf_utils_copy_file(source.c_str(), destination.c_str());
45258191Sjmmv}
46258191Sjmmv
47258191Sjmmvbool
48258191Sjmmvatf::utils::compare_file(const std::string& path, const std::string& contents)
49258191Sjmmv{
50258191Sjmmv    return atf_utils_compare_file(path.c_str(), contents.c_str());
51258191Sjmmv}
52258191Sjmmv
53258191Sjmmvvoid
54258191Sjmmvatf::utils::create_file(const std::string& path, const std::string& contents)
55258191Sjmmv{
56258191Sjmmv    atf_utils_create_file(path.c_str(), "%s", contents.c_str());
57258191Sjmmv}
58258191Sjmmv
59258191Sjmmvbool
60258191Sjmmvatf::utils::file_exists(const std::string& path)
61258191Sjmmv{
62258191Sjmmv    return atf_utils_file_exists(path.c_str());
63258191Sjmmv}
64258191Sjmmv
65258191Sjmmvpid_t
66258191Sjmmvatf::utils::fork(void)
67258191Sjmmv{
68258191Sjmmv    std::cout.flush();
69258191Sjmmv    std::cerr.flush();
70258191Sjmmv    return atf_utils_fork();
71258191Sjmmv}
72258191Sjmmv
73258191Sjmmvbool
74258191Sjmmvatf::utils::grep_file(const std::string& regex, const std::string& path)
75258191Sjmmv{
76258191Sjmmv    return atf_utils_grep_file("%s", path.c_str(), regex.c_str());
77258191Sjmmv}
78258191Sjmmv
79258191Sjmmvbool
80258191Sjmmvatf::utils::grep_string(const std::string& regex, const std::string& str)
81258191Sjmmv{
82258191Sjmmv    return atf_utils_grep_string("%s", str.c_str(), regex.c_str());
83258191Sjmmv}
84258191Sjmmv
85258191Sjmmvvoid
86258191Sjmmvatf::utils::redirect(const int fd, const std::string& path)
87258191Sjmmv{
88258191Sjmmv    if (fd == STDOUT_FILENO)
89258191Sjmmv        std::cout.flush();
90258191Sjmmv    else if (fd == STDERR_FILENO)
91258191Sjmmv        std::cerr.flush();
92258191Sjmmv    atf_utils_redirect(fd, path.c_str());
93258191Sjmmv}
94258191Sjmmv
95258191Sjmmvvoid
96258191Sjmmvatf::utils::wait(const pid_t pid, const int exitstatus,
97258191Sjmmv                 const std::string& expout, const std::string& experr)
98258191Sjmmv{
99258191Sjmmv    atf_utils_wait(pid, exitstatus, expout.c_str(), experr.c_str());
100258191Sjmmv}
101