Thrill  0.1
setenv.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/port/setenv.cpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2016-2018 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #include <tlx/port/setenv.hpp>
12 
13 #include <cstdlib>
14 
15 namespace tlx {
16 
17 // Windows porting madness because setenv() is apparently dangerous
18 #if defined(_MSC_VER)
19 
20 int setenv(const char* name, const char* value, int overwrite) {
21  if (!overwrite) {
22  size_t envsize = 0;
23  int errcode = getenv_s(&envsize, nullptr, 0, name);
24  if (errcode || envsize) return errcode;
25  }
26  return _putenv_s(name, value);
27 }
28 
29 #else
30 
31 int setenv(const char* name, const char* value, int overwrite) {
32  return ::setenv(name, value, overwrite);
33 }
34 
35 #endif
36 
37 } // namespace tlx
38 
39 /******************************************************************************/
int setenv(const char *name, const char *value, int overwrite)
setenv - change or add an environment variable Windows porting madness because setenv() is apparently...
Definition: setenv.cpp:31
int value
Definition: gen_data.py:41