]> git.lyx.org Git - lyx.git/blob - src/support/putenv.C
tostr -> convert and some bformat work
[lyx.git] / src / support / putenv.C
1 /**
2  * \file putenv.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author João Luis M. Assirati
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "support/lyxlib.h"
15
16 #include <cstdlib>
17 #include <string>
18 #include <map>
19
20 using std::string;
21 using std::map;
22
23 bool lyx::support::putenv(string const & varname, string const & value)
24 {
25         static map<string, char *> varmap;
26
27         string str = varname + '=' + value;
28         char * newptr = new char[str.size() + 1];
29         newptr[str.copy(newptr, string::npos)] = '\0';
30         bool status = (::putenv(newptr) == 0);
31
32         char * oldptr = varmap[varname];
33         if (oldptr)
34                 delete oldptr;
35         varmap[varname] = newptr;
36
37         return status;
38 }