Drop main() prototype. Syncs with NetBSD-8
[minix.git] / external / bsd / atf / dist / atf-c++ / config.cpp
blob1890ac0e66c711cdd7e61216ea0d0f1fe4fc4fda
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 #include <map>
32 extern "C" {
33 #include "atf-c/config.h"
36 #include "config.hpp"
38 #include "detail/env.hpp"
39 #include "detail/sanity.hpp"
41 static std::map< std::string, std::string > m_variables;
44 // Adds all predefined standard build-time variables to the m_variables
45 // map, considering the values a user may have provided in the environment.
47 // Can only be called once during the program's lifetime.
49 static
50 void
51 init_variables(void)
53 PRE(m_variables.empty());
55 m_variables["atf_build_cc"] = atf_config_get("atf_build_cc");
56 m_variables["atf_build_cflags"] = atf_config_get("atf_build_cflags");
57 m_variables["atf_build_cpp"] = atf_config_get("atf_build_cpp");
58 m_variables["atf_build_cppflags"] = atf_config_get("atf_build_cppflags");
59 m_variables["atf_build_cxx"] = atf_config_get("atf_build_cxx");
60 m_variables["atf_build_cxxflags"] = atf_config_get("atf_build_cxxflags");
61 m_variables["atf_includedir"] = atf_config_get("atf_includedir");
62 m_variables["atf_libexecdir"] = atf_config_get("atf_libexecdir");
63 m_variables["atf_pkgdatadir"] = atf_config_get("atf_pkgdatadir");
64 m_variables["atf_shell"] = atf_config_get("atf_shell");
65 m_variables["atf_workdir"] = atf_config_get("atf_workdir");
67 POST(!m_variables.empty());
70 const std::string&
71 atf::config::get(const std::string& varname)
73 if (m_variables.empty())
74 init_variables();
76 PRE(has(varname));
77 return m_variables[varname];
80 const std::map< std::string, std::string >&
81 atf::config::get_all(void)
83 if (m_variables.empty())
84 init_variables();
86 return m_variables;
89 bool
90 atf::config::has(const std::string& varname)
92 if (m_variables.empty())
93 init_variables();
95 return m_variables.find(varname) != m_variables.end();
98 extern "C" {
99 void __atf_config_reinit(void);
102 namespace atf {
103 namespace config {
105 // Auxiliary function for the t_config test program so that it can
106 // revert the configuration's global status to an empty state and
107 // do new tests from there on.
109 // Ideally this shouldn't be part of the production library... but
110 // this is so small that it does not matter.
112 void
113 __reinit(void)
115 __atf_config_reinit();
116 m_variables.clear();
118 } // namespace config
119 } // namespace atf