From 2a1e0645f33c2501c6f38309297ef870951ecddf Mon Sep 17 00:00:00 2001 From: Caol?n McNamara Date: Wed, 14 Jul 2010 12:19:12 +0100 Subject: [PATCH] cmcfixes76: #i112656# osl_setEnvironment/osl_clearEnvironment, can't find out of os/2 has setenv/unsetenv, so use putenv which I can definitely see in the ancient emx headers --- sal/osl/os2/process_impl.cxx | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/sal/osl/os2/process_impl.cxx b/sal/osl/os2/process_impl.cxx index 307f311e3730..be6bb1898e65 100644 --- a/sal/osl/os2/process_impl.cxx +++ b/sal/osl/os2/process_impl.cxx @@ -306,11 +306,26 @@ oslProcessError SAL_CALL osl_setEnvironment(rtl_uString* pustrEnvVar, rtl_uStrin if (pstr_env_var != 0 && pstr_val != 0) { - if (setenv(rtl_string_getStr(pstr_env_var), rtl_string_getStr(pstr_val), 1) == 0) + //Can't determine if OS/2 EMX has a working setenv or not, so use putenv, + //feel free to use setenv here if its available and works + rtl_String * pBuffer = NULL; + + sal_Int32 nCapacity = rtl_stringbuffer_newFromStringBuffer( &pBuffer, + rtl_string_getLength(pstr_env_var) + rtl_string_getLength(pstr_val) + 1, + pstr_env_var ); + rtl_stringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, "=", 1); + rtl_stringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, + rtl_string_getStr(pstr_val), rtl_string_getLength(pstr_val) ); + + rtl_string_acquire(pBuffer); // argument to putenv must leak on success + + if (putenv(rtl_string_getStr(pBuffer)) == 0) result = osl_Process_E_None; + else + rtl_string_release(pBuffer); } - if (pstr_val != 0) + if (pstr_val) rtl_string_release(pstr_val); if (pstr_env_var != 0) @@ -337,8 +352,21 @@ oslProcessError SAL_CALL osl_clearEnvironment(rtl_uString* pustrEnvVar) if (pstr_env_var) { - if (unsetenv(rtl_string_getStr(pstr_env_var)) == 0) + //Can't determine if OS/2 EMX has a working unsetenv or not, so use putenv, + //feel free to use unsetenv here if its available and works + rtl_String * pBuffer = NULL; + + sal_Int32 nCapacity = rtl_stringbuffer_newFromStringBuffer( &pBuffer, + rtl_string_getLength(pstr_env_var) + 1, pstr_env_var ); + rtl_stringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, "=", 1); + + rtl_string_acquire(pBuffer); // argument to putenv must leak on success + + if (putenv(rtl_string_getStr(pBuffer)) == 0) result = osl_Process_E_None; + else + rtl_string_release(pBuffer); + rtl_string_release(pstr_env_var); } -- 2.11.4.GIT