env.cpp revision 275988
1// Copyright (c) 2007 The NetBSD Foundation, Inc. 2// All rights reserved. 3// 4// Redistribution and use in source and binary forms, with or without 5// modification, are permitted provided that the following conditions 6// are met: 7// 1. Redistributions of source code must retain the above copyright 8// notice, this list of conditions and the following disclaimer. 9// 2. Redistributions in binary form must reproduce the above copyright 10// notice, this list of conditions and the following disclaimer in the 11// documentation and/or other materials provided with the distribution. 12// 13// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 14// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 15// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 16// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 18// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 20// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 22// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 24// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 26#include "atf-c++/detail/env.hpp" 27 28extern "C" { 29#include "atf-c/detail/env.h" 30#include "atf-c/error.h" 31} 32 33#include "atf-c++/detail/exceptions.hpp" 34#include "atf-c++/detail/sanity.hpp" 35 36namespace impl = atf::env; 37#define IMPL_NAME "atf::env" 38 39// ------------------------------------------------------------------------ 40// Free functions. 41// ------------------------------------------------------------------------ 42 43std::string 44impl::get(const std::string& name) 45{ 46 return atf_env_get(name.c_str()); 47} 48 49std::string 50impl::get(const std::string& name, const std::string& default_value) 51{ 52 return atf_env_get_with_default(name.c_str(), default_value.c_str()); 53} 54 55bool 56impl::has(const std::string& name) 57{ 58 return atf_env_has(name.c_str()); 59} 60 61void 62impl::set(const std::string& name, const std::string& val) 63{ 64 atf_error_t err = atf_env_set(name.c_str(), val.c_str()); 65 if (atf_is_error(err)) 66 throw_atf_error(err); 67} 68 69void 70impl::unset(const std::string& name) 71{ 72 atf_error_t err = atf_env_unset(name.c_str()); 73 if (atf_is_error(err)) 74 throw_atf_error(err); 75} 76