1 // Copyright (c) 2007 The NetBSD Foundation, Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions
7 // 1. Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // 2. Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
13 // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14 // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include "atf-c++/utils.hpp"
29 #include "atf-c/utils.h"
36 atf::utils::cat_file(const std::string& path, const std::string& prefix)
38 atf_utils_cat_file(path.c_str(), prefix.c_str());
42 atf::utils::copy_file(const std::string& source, const std::string& destination)
44 atf_utils_copy_file(source.c_str(), destination.c_str());
48 atf::utils::compare_file(const std::string& path, const std::string& contents)
50 return atf_utils_compare_file(path.c_str(), contents.c_str());
54 atf::utils::create_file(const std::string& path, const std::string& contents)
56 atf_utils_create_file(path.c_str(), "%s", contents.c_str());
60 atf::utils::file_exists(const std::string& path)
62 return atf_utils_file_exists(path.c_str());
66 atf::utils::fork(void)
70 return atf_utils_fork();
74 atf::utils::grep_file(const std::string& regex, const std::string& path)
76 return atf_utils_grep_file("%s", path.c_str(), regex.c_str());
80 atf::utils::grep_string(const std::string& regex, const std::string& str)
82 return atf_utils_grep_string("%s", str.c_str(), regex.c_str());
86 atf::utils::redirect(const int fd, const std::string& path)
88 if (fd == STDOUT_FILENO)
90 else if (fd == STDERR_FILENO)
92 atf_utils_redirect(fd, path.c_str());
96 atf::utils::wait(const pid_t pid, const int exitstatus,
97 const std::string& expout, const std::string& experr)
99 atf_utils_wait(pid, exitstatus, expout.c_str(), experr.c_str());