| 1 | // |
| 2 | // Copyright (c) 2022 Alexander Grund |
| 3 | // |
| 4 | // Distributed under the Boost Software License, Version 1.0. |
| 5 | // https://www.boost.org/LICENSE_1_0.txt |
| 6 | |
| 7 | // setenv etc. are an extension, so we need this for Cygwin and MinGW |
| 8 | #if defined(__CYGWIN__) && !defined(_GNU_SOURCE) |
| 9 | // The setenv family of functions is an extension on Cygwin |
| 10 | # define _GNU_SOURCE 1 |
| 11 | #endif |
| 12 | #if defined(__MINGW32__) && defined(__STRICT_ANSI__) |
| 13 | // On MinGW-w64 the workaround is not needed and leads to warnings |
| 14 | # include <_mingw.h> |
| 15 | # ifndef __MINGW64_VERSION_MAJOR |
| 16 | # undef __STRICT_ANSI__ |
| 17 | # endif |
| 18 | #endif |
| 19 | |
| 20 | #include <boostLocale/test/test_helpers.hpp> |
| 21 | #include <cstdlib> |
| 22 | #ifdef BOOST_WINDOWS |
| 23 | # include <list> |
| 24 | # include <string> |
| 25 | #endif |
| 26 | |
| 27 | namespace boost { namespace locale { namespace test { |
| 28 | #ifdef BOOST_WINDOWS |
| 29 | // Needed as strings become part of the environment |
| 30 | static std::list<std::string> env_values; |
| 31 | |
| 32 | int setenv(const char* key, const char* value) |
| 33 | { |
| 34 | env_values.push_back(key + std::string("=" ) + value); |
| 35 | return _putenv(env_values.back().c_str()); |
| 36 | } |
| 37 | |
| 38 | int unsetenv(const char* key) |
| 39 | { |
| 40 | return setenv(key, "" ); |
| 41 | } |
| 42 | |
| 43 | #else |
| 44 | int setenv(const char* key, const char* value) |
| 45 | { |
| 46 | return ::setenv(name: key, value: value, replace: 1); |
| 47 | } |
| 48 | |
| 49 | int unsetenv(const char* key) |
| 50 | { |
| 51 | return ::unsetenv(name: key); |
| 52 | } |
| 53 | #endif |
| 54 | }}} // namespace boost::locale::test |
| 55 | |