set_env.hpp
Go to the documentation of this file.
1// Copyright (c) 2006, 2007 Julio M. Merino Vidal
2// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3// Copyright (c) 2009 Boris Schaeling
4// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5// Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
6//
7// Distributed under the Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9
10#pragma once
11
12#include <string>
13
15#include <boost/range/algorithm/transform.hpp>
16#include <boost/shared_array.hpp>
17
19{
20
21 template <class Range>
23 {
24 private:
25 static char*
26 get_ptr(const std::string& s)
27 {
28 return const_cast<char*>(s.c_str());
29 }
30
31 public:
32 explicit set_env_(const Range& envs) : env_(new char*[envs.size() + 1])
33 {
34 boost::transform(envs, env_.get(), get_ptr);
35 env_[envs.size()] = 0;
36 }
37
38 template <class PosixExecutor>
39 void
40 on_fork_setup(PosixExecutor& e) const
41 {
42 e.env = env_.get();
43 }
44
45 private:
46 boost::shared_array<char*> env_;
47 };
48
49 template <class Range>
50 set_env_<Range>
51 set_env(const Range& envs)
52 {
53 return set_env_<Range>(envs);
54 }
55
56} // namespace boost::process::posix::initializers
void on_fork_setup(PosixExecutor &e) const
Definition set_env.hpp:40
set_env_< Range > set_env(const Range &envs)
Definition set_env.hpp:51