1c243e490SMarcel Moolenaar // Copyright (c) 2007 The NetBSD Foundation, Inc.
2c243e490SMarcel Moolenaar // All rights reserved.
3c243e490SMarcel Moolenaar //
4c243e490SMarcel Moolenaar // Redistribution and use in source and binary forms, with or without
5c243e490SMarcel Moolenaar // modification, are permitted provided that the following conditions
6c243e490SMarcel Moolenaar // are met:
7c243e490SMarcel Moolenaar // 1. Redistributions of source code must retain the above copyright
8c243e490SMarcel Moolenaar // notice, this list of conditions and the following disclaimer.
9c243e490SMarcel Moolenaar // 2. Redistributions in binary form must reproduce the above copyright
10c243e490SMarcel Moolenaar // notice, this list of conditions and the following disclaimer in the
11c243e490SMarcel Moolenaar // documentation and/or other materials provided with the distribution.
12c243e490SMarcel Moolenaar //
13c243e490SMarcel Moolenaar // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14c243e490SMarcel Moolenaar // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15c243e490SMarcel Moolenaar // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16c243e490SMarcel Moolenaar // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17c243e490SMarcel Moolenaar // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18c243e490SMarcel Moolenaar // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19c243e490SMarcel Moolenaar // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20c243e490SMarcel Moolenaar // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21c243e490SMarcel Moolenaar // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22c243e490SMarcel Moolenaar // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23c243e490SMarcel Moolenaar // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24c243e490SMarcel Moolenaar // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25c243e490SMarcel Moolenaar
260677dfd1SJulio Merino #if !defined(ATF_CXX_UTILS_HPP)
270677dfd1SJulio Merino #define ATF_CXX_UTILS_HPP
28c243e490SMarcel Moolenaar
29a18eacbeSJulio Merino extern "C" {
30a18eacbeSJulio Merino #include <unistd.h>
31a18eacbeSJulio Merino }
32a18eacbeSJulio Merino
33a18eacbeSJulio Merino #include <string>
34c243e490SMarcel Moolenaar
35c243e490SMarcel Moolenaar namespace atf {
36c243e490SMarcel Moolenaar namespace utils {
37c243e490SMarcel Moolenaar
38a18eacbeSJulio Merino void cat_file(const std::string&, const std::string&);
39a18eacbeSJulio Merino bool compare_file(const std::string&, const std::string&);
40a18eacbeSJulio Merino void copy_file(const std::string&, const std::string&);
41a18eacbeSJulio Merino void create_file(const std::string&, const std::string&);
42a18eacbeSJulio Merino bool file_exists(const std::string&);
43a18eacbeSJulio Merino pid_t fork(void);
44*c203bd70SAlex Richardson void reset_resultsfile(void);
45a18eacbeSJulio Merino bool grep_file(const std::string&, const std::string&);
46a18eacbeSJulio Merino bool grep_string(const std::string&, const std::string&);
47a18eacbeSJulio Merino void redirect(const int, const std::string&);
48a18eacbeSJulio Merino void wait(const pid_t, const int, const std::string&, const std::string&);
49c243e490SMarcel Moolenaar
50a18eacbeSJulio Merino template< typename Collection >
51a18eacbeSJulio Merino bool
grep_collection(const std::string & regexp,const Collection & collection)52a18eacbeSJulio Merino grep_collection(const std::string& regexp, const Collection& collection)
53c243e490SMarcel Moolenaar {
54a18eacbeSJulio Merino for (typename Collection::const_iterator iter = collection.begin();
55a18eacbeSJulio Merino iter != collection.end(); ++iter) {
56a18eacbeSJulio Merino if (grep_string(regexp, *iter))
57a18eacbeSJulio Merino return true;
58c243e490SMarcel Moolenaar }
59a18eacbeSJulio Merino return false;
60c243e490SMarcel Moolenaar }
61c243e490SMarcel Moolenaar
62c243e490SMarcel Moolenaar } // namespace utils
63c243e490SMarcel Moolenaar } // namespace atf
64c243e490SMarcel Moolenaar
650677dfd1SJulio Merino #endif // !defined(ATF_CXX_UTILS_HPP)
66