1240116Smarcel// Copyright (c) 2007 The NetBSD Foundation, Inc.
2240116Smarcel// All rights reserved.
3240116Smarcel//
4240116Smarcel// Redistribution and use in source and binary forms, with or without
5240116Smarcel// modification, are permitted provided that the following conditions
6240116Smarcel// are met:
7240116Smarcel// 1. Redistributions of source code must retain the above copyright
8240116Smarcel//    notice, this list of conditions and the following disclaimer.
9240116Smarcel// 2. Redistributions in binary form must reproduce the above copyright
10240116Smarcel//    notice, this list of conditions and the following disclaimer in the
11240116Smarcel//    documentation and/or other materials provided with the distribution.
12240116Smarcel//
13240116Smarcel// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14240116Smarcel// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15240116Smarcel// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16240116Smarcel// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17240116Smarcel// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18240116Smarcel// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19240116Smarcel// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20240116Smarcel// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21240116Smarcel// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22240116Smarcel// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23240116Smarcel// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24240116Smarcel// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25240116Smarcel
26273929Sjmmv#include "atf-c++/detail/env.hpp"
27273929Sjmmv
28240116Smarcelextern "C" {
29273929Sjmmv#include "atf-c/detail/env.h"
30273929Sjmmv#include "atf-c/error.h"
31240116Smarcel}
32240116Smarcel
33273929Sjmmv#include "atf-c++/detail/exceptions.hpp"
34273929Sjmmv#include "atf-c++/detail/sanity.hpp"
35240116Smarcel
36240116Smarcelnamespace impl = atf::env;
37240116Smarcel#define IMPL_NAME "atf::env"
38240116Smarcel
39240116Smarcel// ------------------------------------------------------------------------
40240116Smarcel// Free functions.
41240116Smarcel// ------------------------------------------------------------------------
42240116Smarcel
43240116Smarcelstd::string
44240116Smarcelimpl::get(const std::string& name)
45240116Smarcel{
46240116Smarcel    return atf_env_get(name.c_str());
47240116Smarcel}
48240116Smarcel
49273929Sjmmvstd::string
50273929Sjmmvimpl::get(const std::string& name, const std::string& default_value)
51273929Sjmmv{
52273929Sjmmv    return atf_env_get_with_default(name.c_str(), default_value.c_str());
53273929Sjmmv}
54273929Sjmmv
55240116Smarcelbool
56240116Smarcelimpl::has(const std::string& name)
57240116Smarcel{
58240116Smarcel    return atf_env_has(name.c_str());
59240116Smarcel}
60240116Smarcel
61240116Smarcelvoid
62240116Smarcelimpl::set(const std::string& name, const std::string& val)
63240116Smarcel{
64240116Smarcel    atf_error_t err = atf_env_set(name.c_str(), val.c_str());
65240116Smarcel    if (atf_is_error(err))
66240116Smarcel        throw_atf_error(err);
67240116Smarcel}
68240116Smarcel
69240116Smarcelvoid
70240116Smarcelimpl::unset(const std::string& name)
71240116Smarcel{
72240116Smarcel    atf_error_t err = atf_env_unset(name.c_str());
73240116Smarcel    if (atf_is_error(err))
74240116Smarcel        throw_atf_error(err);
75240116Smarcel}
76