Environment.cc 1.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
// (C) Copyright 2015 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk,  Inc.,  and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of  this information  by  anyone  other  than  authorized
// employees of Autodesk, Inc.  is granted  only under a written
// non-disclosure agreement,  expressly  prescribing  the  scope
// and manner of such use.

#include "Base/Security/Mandatory.hh"
#include "Environment.hh"

namespace System {
namespace Environment {

bool variable(const char* _vrbl_name, std::string& _vrbl)
{
#ifdef WIN32 // The Windows implementation uses the secure getenv_s()
  size_t char_nmbr;
  getenv_s(&char_nmbr, nullptr, 0, _vrbl_name);
  if (char_nmbr == 0)
    return false;
  _vrbl.resize(char_nmbr);
  getenv_s(&char_nmbr, &_vrbl[0], char_nmbr, _vrbl_name);
  _vrbl.resize(char_nmbr - 1); // remove the trailing \0 char
#else
  const char* vrbl_env = getenv("REFORM_DEB_CONFIG");
  if (vrbl_env == nullptr)
    return false;
  _vrbl = vrbl_env;
#endif
  return true;
}

}//namespace Environment 
}//namespace System