Skip to content

Commit

Permalink
use rcutils_get_env, remove added namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Dirk Thomas <[email protected]>
  • Loading branch information
dirk-thomas committed Jan 15, 2020
1 parent 9752a8f commit 1b54007
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions rmw_implementation/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "rcutils/allocator.h"
#include "rcutils/format_string.h"
#include "rcutils/get_env.h"
#include "rcutils/types/string_array.h"

#include "Poco/SharedLibrary.h"
Expand All @@ -35,29 +36,14 @@
#define STRINGIFY_(s) #s
#define STRINGIFY(s) STRINGIFY_(s)

namespace
{

// TODO(eric.cousineau): Use rcutils_get_env pending debugging usage on
// Windows.
std::string get_env_var(const char * env_var)
{
char * value = nullptr;
#ifndef _WIN32
value = getenv(env_var);
#else
size_t value_size;
_dupenv_s(&value, &value_size, env_var);
#endif
std::string value_str = "";
if (value) {
value_str = value;
#ifdef _WIN32
free(value);
#endif
const char * value{};
const char * err = rcutils_get_env(env_var, &value);
if (err) {
throw std::runtime_error(err);
}
// printf("get_env_var(%s) = %s\n", env_var, value_str.c_str());
return value_str;
return value ? value : "";
}

Poco::SharedLibrary *
Expand Down Expand Up @@ -115,8 +101,6 @@ get_symbol(const char * symbol_name)
return lib->getSymbol(symbol_name);
}

} // namespace

#ifdef __cplusplus
extern "C"
{
Expand Down

0 comments on commit 1b54007

Please sign in to comment.