From 22bcfce98768700048c57f72d6396306ca3b99dd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 24 Feb 2012 20:33:18 +0000 Subject: [PATCH] Add abstractions for (un)setting OS environ variables. --- common/os_process.hpp | 24 ++++++++++++++++++++++++ common/trace_tools_trace.cpp | 8 ++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/common/os_process.hpp b/common/os_process.hpp index f1dd517..ba53408 100644 --- a/common/os_process.hpp +++ b/common/os_process.hpp @@ -31,12 +31,36 @@ #define _OS_PROCESS_HPP_ +#ifdef _WIN32 +#include +#endif + #include "os.hpp" namespace os { +inline void +setEnvironment(const char *name, const char *value) { +#ifdef _WIN32 + SetEnvironmentVariableA(name, value); +#else + setenv(name, value, 1); +#endif +} + + +inline void +unsetEnvironment(const char *name) { +#ifdef _WIN32 + SetEnvironmentVariableA(name, NULL); +#else + unsetenv(name); +#endif +} + + int execute(char * const * args); diff --git a/common/trace_tools_trace.cpp b/common/trace_tools_trace.cpp index 768fd10..dc40896 100644 --- a/common/trace_tools_trace.cpp +++ b/common/trace_tools_trace.cpp @@ -111,10 +111,10 @@ traceProgram(API api, } /* FIXME: Don't modify the current environment */ - setenv(TRACE_VARIABLE, wrapper.str(), 1); + os::setEnvironment(TRACE_VARIABLE, wrapper.str()); if (output) { - setenv("TRACE_FILE", output, 1); + os::setEnvironment("TRACE_FILE", output); } if (verbose) { @@ -128,9 +128,9 @@ traceProgram(API api, int status = os::execute(argv); - unsetenv(TRACE_VARIABLE); + os::unsetEnvironment(TRACE_VARIABLE); if (output) { - unsetenv("TRACE_FILE"); + os::unsetEnvironment("TRACE_FILE"); } return status; -- 2.45.2