From e8f5cf2940667a60698d28fe0cae208792357676 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sat, 11 Jan 2003 11:16:36 +0000 Subject: valgrind fixes, and fixes for writing shit all over the environment. yay~!!!!!!! --- otk/display.cc | 11 ++--------- otk/util.cc | 21 ++++++++++++++++++--- otk/util.hh | 1 + 3 files changed, 21 insertions(+), 12 deletions(-) (limited to 'otk') diff --git a/otk/display.cc b/otk/display.cc index 33dca01b..98288bd0 100644 --- a/otk/display.cc +++ b/otk/display.cc @@ -7,6 +7,7 @@ #include "display.hh" #include "screeninfo.hh" #include "gccache.hh" +#include "util.hh" extern "C" { #include @@ -27,10 +28,6 @@ extern "C" { # include #endif // HAVE_STDIO_H -#ifdef HAVE_STDLIB_H -# include -#endif // HAVE_STDLIB_H - #ifdef HAVE_SIGNAL_H # include #endif // HAVE_SIGNAL_H @@ -110,11 +107,7 @@ line argument.\n\n")); // set the DISPLAY environment variable for any lauched children, to the // display we're using, so they open in the right place. // XXX rm -> std::string dtmp = "DISPLAY=" + DisplayString(display); - if (putenv(const_cast((std::string("DISPLAY=") + - DisplayString(display)).c_str()))) { - printf(_("warning: couldn't set environment variable 'DISPLAY'\n")); - perror("putenv()"); - } + putenv(std::string("DISPLAY=") + DisplayString(display)); // find the availability of X extensions we like to use #ifdef XKB diff --git a/otk/util.cc b/otk/util.cc index ebca51d5..a3ec0034 100644 --- a/otk/util.cc +++ b/otk/util.cc @@ -23,6 +23,9 @@ extern "C" { # include #endif // HAVE_PROCESS_H __EMX__ +#include "gettext.h" +#define _(str) gettext(str) + #include } @@ -48,9 +51,8 @@ void bexec(const string& command, const string& displaystring) { #ifndef __EMX__ if (! fork()) { setsid(); - int ret = putenv(const_cast(displaystring.c_str())); - assert(ret != -1); - ret = execl("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL); + putenv(displaystring); + int ret = execl("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL); exit(ret); } #else // __EMX__ @@ -101,6 +103,19 @@ string itostring(long i) { return tmp; } +void putenv(const std::string &data) +{ + char *c = new char[data.size() + 1]; + std::string::size_type i, max; + for (i = 0, max = data.size(); i < max; ++i) + c[i] = data[i]; + c[i] = 0; + if (::putenv(c)) { + printf(_("warning: couldn't set environment variable\n")); + perror("putenv()"); + } +} + string basename (const string& path) { string::size_type slash = path.rfind('/'); if (slash == string::npos) diff --git a/otk/util.hh b/otk/util.hh index 2664c1fa..2325ebf0 100644 --- a/otk/util.hh +++ b/otk/util.hh @@ -40,6 +40,7 @@ inline std::string itostring(unsigned int i) inline std::string itostring(int i) { return itostring((long) i); } +void putenv(const std::string &data); std::string basename(const std::string& path); -- cgit v1.2.3