azure-sdk-for-cpp/samples/helpers/get-env/inc/get_env.hpp
Larry Osterman af7281ef1a
Updated and add samples for Attestation service. (#3448)
* Moved samples around to meet new recommendations; added a couple of additional tests.
* Reworked attestation to include RetrieveAttestationValidationCollateral
* Attestation sample readme updates
* TPM doesn't need to retrieve response validation collateral
* Added cautionary warning about the dangers of overriding the TearDown method from inside a test case
* Added attestation team members to codeowners for attestation SDK
* Remove CODEOWNERS from cspell checks
* Don't hold a lock across retrieving the signers over the network
* Updated snippets in readme; clang-format
2022-03-22 14:29:03 -07:00

52 lines
1.1 KiB
C++

// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
// Since `getenv()` may generate warnings on MSVC, and is not available on UWP, sample code
// gets cluttered with insignificant nuances. This file makes it so that `std::getenv()` compiles
// and works the same on Linux, macOS, Win32, and UWP.
#pragma once
#if !defined(_MSC_VER)
// Linux and macOS
#include <cstdlib>
#else
#define _CRT_SECURE_NO_WARNINGS
#if !defined(WIN32_LEAN_AND_MEAN)
#define WIN32_LEAN_AND_MEAN
#endif
#if !defined(NOMINMAX)
#define NOMINMAX
#endif
#include <windows.h>
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP
// Win32
#include <cstdlib>
#else
// UWP
namespace std {
char* getenv(const char* name);
}
#endif
#endif
#include <stdexcept>
#include <string>
struct GetEnvHelper
{
static std::string GetEnv(char const* env)
{
auto const val = std::getenv(env);
if (val == nullptr)
{
throw std::runtime_error("Could not find required environment variable: " + std::string(env));
}
return std::string(val);
}
};