// Copyright (c) 2009 The NetBSD Foundation, Inc.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions5// are met:6// 1. Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// 2. Redistributions in binary form must reproduce the above copyright9// notice, this list of conditions and the following disclaimer in the10// documentation and/or other materials provided with the distribution.11//12// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND13// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,14// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF15// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE19// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS20// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER21// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN23// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2425#include "atf-c++/build.hpp"2627extern "C" {28#include "atf-c/build.h"29#include "atf-c/error.h"30#include "atf-c/utils.h"31}3233#include "atf-c++/detail/exceptions.hpp"34#include "atf-c++/detail/process.hpp"3536namespace impl = atf::build;37#define IMPL_NAME "atf::build"3839// ------------------------------------------------------------------------40// Auxiliary functions.41// ------------------------------------------------------------------------4243inline44atf::process::argv_array45cargv_to_argv(const atf_list_t* l)46{47std::vector< const char* > aux;4849atf_list_citer_t iter;50atf_list_for_each_c(iter, l)51aux.push_back(static_cast< const char* >(atf_list_citer_data(iter)));5253return atf::process::argv_array(aux);54}5556inline57atf::process::argv_array58cargv_to_argv_and_free(char** l)59{60try {61atf::process::argv_array argv((const char* const*)l);62atf_utils_free_charpp(l);63return argv;64} catch (...) {65atf_utils_free_charpp(l);66throw;67}68}6970// ------------------------------------------------------------------------71// Free functions.72// ------------------------------------------------------------------------7374atf::process::argv_array75impl::c_o(const std::string& sfile, const std::string& ofile,76const atf::process::argv_array& optargs)77{78char** l;7980atf_error_t err = atf_build_c_o(sfile.c_str(), ofile.c_str(),81optargs.exec_argv(), &l);82if (atf_is_error(err))83throw_atf_error(err);8485return cargv_to_argv_and_free(l);86}8788atf::process::argv_array89impl::cpp(const std::string& sfile, const std::string& ofile,90const atf::process::argv_array& optargs)91{92char** l;9394atf_error_t err = atf_build_cpp(sfile.c_str(), ofile.c_str(),95optargs.exec_argv(), &l);96if (atf_is_error(err))97throw_atf_error(err);9899return cargv_to_argv_and_free(l);100}101102atf::process::argv_array103impl::cxx_o(const std::string& sfile, const std::string& ofile,104const atf::process::argv_array& optargs)105{106char** l;107108atf_error_t err = atf_build_cxx_o(sfile.c_str(), ofile.c_str(),109optargs.exec_argv(), &l);110if (atf_is_error(err))111throw_atf_error(err);112113return cargv_to_argv_and_free(l);114}115116117