g4tools
5.4.0
g4tools
tools
put_env
Go to the documentation of this file.
1
// Copyright (C) 2010, Guy Barrand. All rights reserved.
2
// See the file tools.license for terms.
3
4
#ifndef tools_put_env
5
#define tools_put_env
6
7
//WARNING : CYGWIN/gnu/std=c++11 : putenv, setenv not found.
8
9
#include "
get_env
"
10
11
#include "
cstr
"
12
13
namespace
tools
{
14
15
inline
bool
put_env
(
const
std::string& a_env,
const
std::string& a_value){
16
std::string
value
= a_env+
"="
+a_value;
17
#ifdef TOOLS_MEM
18
if
(::putenv(
str_dup
(
value
.c_str(),
false
)))
return
false
;
19
#else
20
if
(::putenv(
str_dup
(
value
.c_str())))
return
false
;
21
#endif
22
//check:
23
std::string s;
24
if
(!
get_env
(a_env,s))
return
false
;
25
if
(s!=a_value)
return
false
;
26
return
true
;
27
}
28
29
inline
bool
rm_env
(
const
std::string& a_env){
30
#ifdef _MSC_VER
31
std::string
value
= a_env+
"="
;
32
#ifdef TOOLS_MEM
33
if
(::putenv(
str_dup
(
value
.c_str(),
false
)))
return
false
;
34
#else
35
if
(::putenv(
str_dup
(
value
.c_str())))
return
false
;
36
#endif
37
#else
38
::unsetenv(a_env.c_str());
39
#endif
40
return
true
;
41
}
42
43
}
44
45
#endif
tools::value
Definition:
value:18
tools::get_env
bool get_env(const std::string &a_string, std::string &a_value)
Definition:
get_env:18
cstr
get_env
tools::put_env
bool put_env(const std::string &a_env, const std::string &a_value)
Definition:
put_env:15
tools
inlined C code : ///////////////////////////////////
Definition:
aida_ntuple:26
tools::rm_env
bool rm_env(const std::string &a_env)
Definition:
put_env:29
tools::str_dup
char * str_dup(const char *a_cstr)
Definition:
cstr:30
Generated by
1.8.20