bincimap

Log | Files | Refs | LICENSE

tools.cc (2126B)


      1 /* -*- Mode: c++; -*- */
      2 /*  --------------------------------------------------------------------
      3  *  Filename:
      4  *    tools.cc
      5  *  
      6  *  Description:
      7  *    Implementation of miscellaneous tools.
      8  *
      9  *  Authors:
     10  *    Andreas Aardal Hanssen <andreas-binc curly bincimap spot org>
     11  *
     12  *  Bugs:
     13  *
     14  *  ChangeLog:
     15  *
     16  *  --------------------------------------------------------------------
     17  *  Copyright 2002-2005 Andreas Aardal Hanssen
     18  *
     19  *  This program is free software; you can redistribute it and/or modify
     20  *  it under the terms of the GNU General Public License as published by
     21  *  the Free Software Foundation; either version 2 of the License, or
     22  *  (at your option) any later version.
     23  *
     24  *  This program is distributed in the hope that it will be useful,
     25  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     26  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     27  *  GNU General Public License for more details.
     28  *
     29  *  You should have received a copy of the GNU General Public License
     30  *  along with this program; if not, write to the Free Software
     31  *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
     32  *  --------------------------------------------------------------------
     33  */
     34 #ifdef HAVE_CONFIG_H
     35 #include <config.h>
     36 #endif
     37 #include <errno.h>
     38 #include <cstdlib>
     39 
     40 #include "tools.h"
     41 
     42 #include <cstring>
     43 
     44 using namespace ::std;
     45 using namespace Binc;
     46 
     47 //------------------------------------------------------------------------
     48 Tools::Tools(void)
     49 {
     50 }
     51 
     52 //------------------------------------------------------------------------
     53 Tools &Tools::getInstance(void)
     54 {
     55   static Tools tools;
     56   return tools;
     57 }
     58 
     59 //------------------------------------------------------------------------
     60 void Tools::setenv(const string &key, const string &value) const
     61 {
     62   char *c = strdup((key + "=" + value).c_str());
     63   putenv(c);
     64 }
     65 
     66 //------------------------------------------------------------------------
     67 string Tools::getenv(const string &key) const
     68 {
     69   static const string NIL = "";
     70 
     71   const char *c = ::getenv((char *)key.c_str());
     72   if (c == 0)
     73     return NIL;
     74   else
     75     return string(c);
     76 }