diff options
author | Alex Zolotarev <alex@maps.me> | 2015-12-15 16:15:59 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-12-15 17:10:37 +0300 |
commit | 6f7399ceee320bab04003b7b7e07a42bac8a0804 (patch) | |
tree | f5edaff0d4530975be83bdf66991c5ea4507b78a /std | |
parent | 00dd0708ad64967c6cf2df4683afe228b47943f1 (diff) |
setenv support for MSVC.
Diffstat (limited to 'std')
-rw-r--r-- | std/cstdlib.hpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/std/cstdlib.hpp b/std/cstdlib.hpp index e119843d52..8268726dcf 100644 --- a/std/cstdlib.hpp +++ b/std/cstdlib.hpp @@ -1,11 +1,26 @@ #pragma once +#include "target_os.hpp" + #ifdef new #undef new #endif #include <cstdlib> +// setenv is absent in MSVC. +#ifdef OMIM_OS_WINDOWS_NATIVE +#include <cstdio> // Need it for snprintf. +inline int setenv(char const * name, char const * value, int /*overwrite*/) +{ + char buffer[255]; + int const err = ::snprintf(buffer, sizeof(buffer), "%s=%s", name, value); + if (err < 0 || err >= sizeof(buffer)) + return -1; + return ::_putenv(buffer); +} +#endif + #ifdef DEBUG_NEW #define new DEBUG_NEW #endif |