summaryrefslogtreecommitdiff
path: root/src/tools.cc
blob: 1b6e28a44e945dc754a272bd8f7227210d7604b4 (plain)
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
38
39
40
/**
 *  @file  tools.cc
 *  @brief  Implementation of miscellaneous tools.
 *  @author Andreas Aardal Hanssen
 *  @date 2002-2005
 */

#include "tools.h"

#include <cstring>

#include <errno.h>

using namespace Binc;
using std::string;

Tools::Tools(void) {}

Tools &Tools::getInstance(void)
{
  static Tools tools;
  return tools;
}

void Tools::setenv(const string &key, const string &value) const
{
  char *c = strdup((key + "=" + value).c_str());
  putenv(c);
}

string Tools::getenv(const string &key) const
{
  static const string NIL = "";

  const char *c = ::getenv((char *)key.c_str());
  if (c == nullptr)
    return NIL;
  else
    return string(c);
}