[Libreoffice-commits] .: tools/source vcl/unx

Caolán McNamara caolan at kemper.freedesktop.org
Mon Oct 18 08:05:56 PDT 2010


 tools/source/misc/extendapplicationenvironment.cxx |   19 ++-----------
 vcl/unx/gtk/app/gtkdata.cxx                        |    7 ++--
 vcl/unx/source/app/i18n_im.cxx                     |   30 +++++++--------------
 vcl/unx/source/app/saldata.cxx                     |    6 +---
 4 files changed, 20 insertions(+), 42 deletions(-)

New commits:
commit b8bade71f4cc61d54a8fc07eb388df8be5535308
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Oct 18 15:43:44 2010 +0100

    #i112656# add osl_setEnvironment and osl_clearEnvironment

diff --git a/tools/source/misc/extendapplicationenvironment.cxx b/tools/source/misc/extendapplicationenvironment.cxx
index fc04345..341deee 100644
--- a/tools/source/misc/extendapplicationenvironment.cxx
+++ b/tools/source/misc/extendapplicationenvironment.cxx
@@ -30,8 +30,6 @@
 #include "sal/config.h"
 
 #include <stdlib.h>
-    // not <cstdlib> as putenv is POSIX-only; setenv instead of putenv would be
-    // better but is not supported by Solaris 9 and earlier
 
 #if defined UNX
 #include <sys/resource.h>
@@ -64,10 +62,9 @@ void extendApplicationEnvironment() {
 
     // Make sure URE_BOOTSTRAP environment variable is set (failure is fatal):
     rtl::OUStringBuffer env;
-    env.appendAscii(RTL_CONSTASCII_STRINGPARAM("URE_BOOTSTRAP="));
+    rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("URE_BOOTSTRAP"));
     rtl::OUString uri;
-    if (rtl::Bootstrap::get(
-            rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URE_BOOTSTRAP")), uri))
+    if (rtl::Bootstrap::get(envVar, uri))
     {
         if (!uri.matchIgnoreAsciiCaseAsciiL(
                 RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.pathname:")))
@@ -87,16 +84,8 @@ void extendApplicationEnvironment() {
         env.appendAscii(
             RTL_CONSTASCII_STRINGPARAM(SAL_CONFIGFILE("fundamental")));
     }
-    rtl::OString s;
-    if (!env.makeStringAndClear().convertToString(
-            &s, osl_getThreadTextEncoding(),
-            RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
-            | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))
-    {
-        abort();
-    }
-    rtl_string_acquire(s.pData); // argument to putenv must leak
-    if (putenv(const_cast< char * >(s.getStr())) != 0) {
+    rtl::OUString envValue(env.makeStringAndClear());
+    if (osl_setEnvironment(envVar.pData, envValue.pData) != osl_Process_E_None) {
         abort();
     }
 }
diff --git a/vcl/unx/gtk/app/gtkdata.cxx b/vcl/unx/gtk/app/gtkdata.cxx
index ff2213a..cf21f6e 100644
--- a/vcl/unx/gtk/app/gtkdata.cxx
+++ b/vcl/unx/gtk/app/gtkdata.cxx
@@ -671,9 +671,10 @@ void GtkXLib::Init()
      * the clipboard build another connection
      * to the xserver using $DISPLAY
      */
-    char *pPutEnvIsBroken = g_strdup_printf( "DISPLAY=%s",
-                                             gdk_display_get_name( pGdkDisp ) );
-    putenv( pPutEnvIsBroken );
+    rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("DISPLAY"));
+    const gchar *name = gdk_display_get_name( pGdkDisp );
+    rtl::OUString envValue(name, strlen(name), aEnc);
+    osl_setEnvironment(envVar.pData, envValue.pData);
 
     Display *pDisp = gdk_x11_display_get_xdisplay( pGdkDisp );
 
diff --git a/vcl/unx/source/app/i18n_im.cxx b/vcl/unx/source/app/i18n_im.cxx
index 4c91424..580a251 100644
--- a/vcl/unx/source/app/i18n_im.cxx
+++ b/vcl/unx/source/app/i18n_im.cxx
@@ -37,10 +37,6 @@
 #  endif
 #endif
 #include <poll.h>
-#ifdef SOLARIS
-// for SetSystemEnvironment()
-#include <sal/alloca.h>
-#endif
 
 #include <tools/prex.h>
 #include <X11/Xlocale.h>
@@ -54,6 +50,7 @@
 #include <i18n_status.hxx>
 
 #include <osl/thread.h>
+#include <osl/process.h>
 
 using namespace vcl;
 #include "i18n_cb.hxx"
@@ -180,21 +177,13 @@ SetSystemLocale( const char* p_inlocale )
 
 #ifdef SOLARIS
 static void
-SetSystemEnvironment( const char* p_locale )
+SetSystemEnvironment( const rtl::OUString& rLocale )
 {
-    const char *lc_all = "LC_ALL=%s";
-    const char *lang   = "LANG=%s";
+    rtl::OUString LC_ALL_Var(RTL_CONSTASCII_USTRINGPARAM("LC_ALL"));
+    osl_setEnvironment(LC_ALL_Var.pData, rLocale.pData);
 
-    char *p_buffer;
-
-    if (p_locale != NULL) 
-    {
-        p_buffer = (char*)alloca(10 + strlen(p_locale));
-        sprintf(p_buffer, lc_all, p_locale);
-        putenv(strdup(p_buffer));
-        sprintf(p_buffer, lang, p_locale);
-        putenv(strdup(p_buffer));
-    }     
+    rtl::OUString LANG_Var(RTL_CONSTASCII_USTRINGPARAM("LANG"));
+    osl_setEnvironment(LANG_Var.pData, rLocale.pData);
 }
 #endif
 
@@ -250,13 +239,13 @@ SalI18N_InputMethod::SetLocale( const char* pLocale )
             osl_setThreadTextEncoding (RTL_TEXTENCODING_ISO_8859_1);
             locale = SetSystemLocale( "en_US" );
             #ifdef SOLARIS
-            SetSystemEnvironment( "en_US" );
+            SetSystemEnvironment( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en_US")) );
             #endif
             if (! IsXWindowCompatibleLocale(locale))
             {
                 locale = SetSystemLocale( "C" );
                 #ifdef SOLARIS
-                SetSystemEnvironment( "C" );
+                SetSystemEnvironment( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("C")) );
                 #endif
                 if (! IsXWindowCompatibleLocale(locale))
                     mbUseable = False;
@@ -441,7 +430,8 @@ SalI18N_InputMethod::CreateMethod ( Display *pDisplay )
 
         if ((maMethod == (XIM)NULL) && (getenv("XMODIFIERS") != NULL))
         {
-                putenv (strdup("XMODIFIERS"));
+                rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("XMODIFIERS"));
+                osl_clearEnvironment(envVar.pData);
                 XSetLocaleModifiers("");
                 maMethod = XOpenIM(pDisplay, NULL, NULL, NULL);
                 mbMultiLingual = False;
diff --git a/vcl/unx/source/app/saldata.cxx b/vcl/unx/source/app/saldata.cxx
index deb07c1..9aa5fc5 100644
--- a/vcl/unx/source/app/saldata.cxx
+++ b/vcl/unx/source/app/saldata.cxx
@@ -422,10 +422,8 @@ void SalXLib::Init()
                  * the clipboard build another connection 
                  * to the xserver using $DISPLAY
                  */
-                const char envpre[] = "DISPLAY=";
-                char *envstr = new char[sizeof(envpre)+aDisplay.getLength()];
-                snprintf(envstr, sizeof(envpre)+aDisplay.getLength(), "DISPLAY=%s", aDisplay.getStr());
-                putenv(envstr);
+                 rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("DISPLAY"));
+                 osl_setEnvironment(envVar.pData, aParam.pData);
             }
             break;
         }


More information about the Libreoffice-commits mailing list