From 1b0cb55f07153b33bda16518d97e1b567a8c03cd Mon Sep 17 00:00:00 2001 From: Tom Tan Date: Thu, 9 Sep 2021 15:34:41 -0700 Subject: [PATCH] Cleanup GetEnvironmentVariable and remove unused variable under NO_GETENV --- .../opentelemetry/sdk/common/env_variables.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sdk/include/opentelemetry/sdk/common/env_variables.h b/sdk/include/opentelemetry/sdk/common/env_variables.h index 63d16d12b5..c989b8921d 100644 --- a/sdk/include/opentelemetry/sdk/common/env_variables.h +++ b/sdk/include/opentelemetry/sdk/common/env_variables.h @@ -15,9 +15,8 @@ namespace common // Returns the env variable set. inline const std::string GetEnvironmentVariable(const char *env_var_name) { +#if !defined(NO_GETENV) const char *endpoint_from_env = nullptr; - -#ifndef NO_GETENV # if defined(_MSC_VER) // avoid calling std::getenv which is deprecated in MSVC. size_t required_size = 0; @@ -31,10 +30,12 @@ inline const std::string GetEnvironmentVariable(const char *env_var_name) } # else endpoint_from_env = std::getenv(env_var_name); -# endif -#endif - return endpoint_from_env == nullptr ? std::string() : endpoint_from_env; +# endif // defined(_MSC_VER) + return endpoint_from_env == nullptr ? std::string{} : std::string{endpoint_from_env}; +#else + return std::string{}; +#endif // !defined(NO_GETENV) } } // namespace common } // namespace sdk -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +OPENTELEMETRY_END_NAMESPACE