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.
25*0677dfd1SJulio Merino
26*0677dfd1SJulio Merino #include "atf-c++/detail/env.hpp"
27c243e490SMarcel Moolenaar
28c243e490SMarcel Moolenaar extern "C" {
29*0677dfd1SJulio Merino #include "atf-c/detail/env.h"
30*0677dfd1SJulio Merino #include "atf-c/error.h"
31c243e490SMarcel Moolenaar }
32c243e490SMarcel Moolenaar
33*0677dfd1SJulio Merino #include "atf-c++/detail/exceptions.hpp"
34*0677dfd1SJulio Merino #include "atf-c++/detail/sanity.hpp"
35c243e490SMarcel Moolenaar
36c243e490SMarcel Moolenaar namespace impl = atf::env;
37c243e490SMarcel Moolenaar #define IMPL_NAME "atf::env"
38c243e490SMarcel Moolenaar
39c243e490SMarcel Moolenaar // ------------------------------------------------------------------------
40c243e490SMarcel Moolenaar // Free functions.
41c243e490SMarcel Moolenaar // ------------------------------------------------------------------------
42c243e490SMarcel Moolenaar
43c243e490SMarcel Moolenaar std::string
get(const std::string & name)44c243e490SMarcel Moolenaar impl::get(const std::string& name)
45c243e490SMarcel Moolenaar {
46c243e490SMarcel Moolenaar return atf_env_get(name.c_str());
47c243e490SMarcel Moolenaar }
48c243e490SMarcel Moolenaar
49*0677dfd1SJulio Merino std::string
get(const std::string & name,const std::string & default_value)50*0677dfd1SJulio Merino impl::get(const std::string& name, const std::string& default_value)
51*0677dfd1SJulio Merino {
52*0677dfd1SJulio Merino return atf_env_get_with_default(name.c_str(), default_value.c_str());
53*0677dfd1SJulio Merino }
54*0677dfd1SJulio Merino
55c243e490SMarcel Moolenaar bool
has(const std::string & name)56c243e490SMarcel Moolenaar impl::has(const std::string& name)
57c243e490SMarcel Moolenaar {
58c243e490SMarcel Moolenaar return atf_env_has(name.c_str());
59c243e490SMarcel Moolenaar }
60c243e490SMarcel Moolenaar
61c243e490SMarcel Moolenaar void
set(const std::string & name,const std::string & val)62c243e490SMarcel Moolenaar impl::set(const std::string& name, const std::string& val)
63c243e490SMarcel Moolenaar {
64c243e490SMarcel Moolenaar atf_error_t err = atf_env_set(name.c_str(), val.c_str());
65c243e490SMarcel Moolenaar if (atf_is_error(err))
66c243e490SMarcel Moolenaar throw_atf_error(err);
67c243e490SMarcel Moolenaar }
68c243e490SMarcel Moolenaar
69c243e490SMarcel Moolenaar void
unset(const std::string & name)70c243e490SMarcel Moolenaar impl::unset(const std::string& name)
71c243e490SMarcel Moolenaar {
72c243e490SMarcel Moolenaar atf_error_t err = atf_env_unset(name.c_str());
73c243e490SMarcel Moolenaar if (atf_is_error(err))
74c243e490SMarcel Moolenaar throw_atf_error(err);
75c243e490SMarcel Moolenaar }
76