Remove building with NOCRYPTO option
[minix3.git] / external / bsd / atf / dist / atf-c++ / utils.cpp
blobcc338bb892301724fd4b67e6e7c047a690941cc5
1 //
2 // Automated Testing Framework (atf)
3 //
4 // Copyright (c) 2007 The NetBSD Foundation, Inc.
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
16 // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 extern "C" {
31 #include "atf-c/utils.h"
34 #include <cstdlib>
35 #include <iostream>
37 #include "utils.hpp"
39 void
40 atf::utils::cat_file(const std::string& path, const std::string& prefix)
42 atf_utils_cat_file(path.c_str(), prefix.c_str());
45 void
46 atf::utils::copy_file(const std::string& source, const std::string& destination)
48 atf_utils_copy_file(source.c_str(), destination.c_str());
51 bool
52 atf::utils::compare_file(const std::string& path, const std::string& contents)
54 return atf_utils_compare_file(path.c_str(), contents.c_str());
57 void
58 atf::utils::create_file(const std::string& path, const std::string& contents)
60 atf_utils_create_file(path.c_str(), "%s", contents.c_str());
63 bool
64 atf::utils::file_exists(const std::string& path)
66 return atf_utils_file_exists(path.c_str());
69 pid_t
70 atf::utils::fork(void)
72 std::cout.flush();
73 std::cerr.flush();
74 return atf_utils_fork();
77 bool
78 atf::utils::grep_file(const std::string& regex, const std::string& path)
80 return atf_utils_grep_file("%s", path.c_str(), regex.c_str());
83 bool
84 atf::utils::grep_string(const std::string& regex, const std::string& str)
86 return atf_utils_grep_string("%s", str.c_str(), regex.c_str());
89 void
90 atf::utils::redirect(const int fd, const std::string& path)
92 if (fd == STDOUT_FILENO)
93 std::cout.flush();
94 else if (fd == STDERR_FILENO)
95 std::cerr.flush();
96 atf_utils_redirect(fd, path.c_str());
99 void
100 atf::utils::wait(const pid_t pid, const int exitstatus,
101 const std::string& expout, const std::string& experr)
103 atf_utils_wait(pid, exitstatus, expout.c_str(), experr.c_str());