diff options
author | Caolán McNamara <caolanm@redhat.com> | 2010-10-18 15:45:17 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2010-10-18 15:45:17 +0100 |
commit | c3b0a4073d2e4917c5a010548ae2a1eb5ebbf9a5 (patch) | |
tree | 76a19cfb10c5d1c0070cac7fa8a41cac92c2d33d /sal | |
parent | f7dc4d73859ba109a54d01f137241d7848a587cf (diff) |
#i112656# add osl_setEnvironment and osl_clearEnvironment
Diffstat (limited to 'sal')
-rw-r--r-- | sal/inc/osl/process.h | 15 | ||||
-rw-r--r-- | sal/osl/os2/process_impl.cxx | 92 | ||||
-rw-r--r-- | sal/osl/unx/process_impl.cxx | 107 | ||||
-rw-r--r-- | sal/osl/w32/process.cxx | 19 | ||||
-rwxr-xr-x | sal/util/sal.map | 7 |
5 files changed, 239 insertions, 1 deletions
diff --git a/sal/inc/osl/process.h b/sal/inc/osl/process.h index bccd4c223..7e2c36489 100644 --- a/sal/inc/osl/process.h +++ b/sal/inc/osl/process.h @@ -388,6 +388,21 @@ void SAL_CALL osl_setCommandArgs (int argc, char **argv); */ oslProcessError SAL_CALL osl_getEnvironment(rtl_uString *strVar, rtl_uString **strValue); +/** Set the value of one enviroment variable. + @param strVar [in] denotes the name of the variable to set. + @param strValue [in] string of the new value of environment variable. + + @since UDK 3.2.13 +*/ +oslProcessError SAL_CALL osl_setEnvironment(rtl_uString *strVar, rtl_uString *strValue); + +/** Unsets the value of one enviroment variable. + @param strVar [in] denotes the name of the variable to unset. + + @since UDK 3.2.13 +*/ +oslProcessError SAL_CALL osl_clearEnvironment(rtl_uString *strVar); + /** Get the working directory of the current process as a file URL. The file URL is encoded as common for the OSL file API. diff --git a/sal/osl/os2/process_impl.cxx b/sal/osl/os2/process_impl.cxx index 0e519d979..0c9730d68 100644 --- a/sal/osl/os2/process_impl.cxx +++ b/sal/osl/os2/process_impl.cxx @@ -279,6 +279,98 @@ oslProcessError SAL_CALL osl_getEnvironment(rtl_uString* pustrEnvVar, rtl_uStrin } /*************************************** + osl_setEnvironment(). + **************************************/ +oslProcessError SAL_CALL osl_setEnvironment(rtl_uString* pustrEnvVar, rtl_uString* pustrValue) +{ + oslProcessError result = osl_Process_E_Unknown; + rtl_TextEncoding encoding = osl_getThreadTextEncoding(); + rtl_String* pstr_env_var = 0; + rtl_String* pstr_val = 0; + + OSL_PRECOND(pustrEnvVar, "osl_setEnvironment(): Invalid parameter"); + OSL_PRECOND(pustrValue, "osl_setEnvironment(): Invalid parameter"); + + rtl_uString2String( + &pstr_env_var, + rtl_uString_getStr(pustrEnvVar), rtl_uString_getLength(pustrEnvVar), encoding, + OUSTRING_TO_OSTRING_CVTFLAGS); + + rtl_uString2String( + &pstr_val, + rtl_uString_getStr(pustrValue), rtl_uString_getLength(pustrValue), encoding, + OUSTRING_TO_OSTRING_CVTFLAGS); + + if (pstr_env_var != 0 && pstr_val != 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) + rtl_string_release(pstr_val); + + if (pstr_env_var != 0) + rtl_string_release(pstr_env_var); + + return (result); +} + +/*************************************** + osl_clearEnvironment(). + **************************************/ +oslProcessError SAL_CALL osl_clearEnvironment(rtl_uString* pustrEnvVar) +{ + oslProcessError result = osl_Process_E_Unknown; + rtl_TextEncoding encoding = osl_getThreadTextEncoding(); + rtl_String* pstr_env_var = 0; + + OSL_PRECOND(pustrEnvVar, "osl_setEnvironment(): Invalid parameter"); + + rtl_uString2String( + &pstr_env_var, + rtl_uString_getStr(pustrEnvVar), rtl_uString_getLength(pustrEnvVar), encoding, + OUSTRING_TO_OSTRING_CVTFLAGS); + + if (pstr_env_var) + { + //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); + } + + return (result); +} + +/*************************************** osl_getProcessWorkingDir(). **************************************/ oslProcessError SAL_CALL osl_getProcessWorkingDir(rtl_uString **ppustrWorkingDir) diff --git a/sal/osl/unx/process_impl.cxx b/sal/osl/unx/process_impl.cxx index ab8bc8071..c36505082 100644 --- a/sal/osl/unx/process_impl.cxx +++ b/sal/osl/unx/process_impl.cxx @@ -51,10 +51,11 @@ #define INCLUDED_STRING_H #endif #include "osl/diagnose.h" -#include <osl/file.h> +#include "osl/file.h" #include "osl/module.h" #include "osl/thread.h" #include "rtl/ustring.hxx" +#include "rtl/strbuf.h" #include "file_path_helper.h" @@ -321,6 +322,110 @@ oslProcessError SAL_CALL osl_getEnvironment(rtl_uString* pustrEnvVar, rtl_uStrin } /*************************************** + osl_setEnvironment(). + **************************************/ +oslProcessError SAL_CALL osl_setEnvironment(rtl_uString* pustrEnvVar, rtl_uString* pustrValue) +{ + oslProcessError result = osl_Process_E_Unknown; + rtl_TextEncoding encoding = osl_getThreadTextEncoding(); + rtl_String* pstr_env_var = 0; + rtl_String* pstr_val = 0; + + OSL_PRECOND(pustrEnvVar, "osl_setEnvironment(): Invalid parameter"); + OSL_PRECOND(pustrValue, "osl_setEnvironment(): Invalid parameter"); + + rtl_uString2String( + &pstr_env_var, + rtl_uString_getStr(pustrEnvVar), rtl_uString_getLength(pustrEnvVar), encoding, + OUSTRING_TO_OSTRING_CVTFLAGS); + + rtl_uString2String( + &pstr_val, + rtl_uString_getStr(pustrValue), rtl_uString_getLength(pustrValue), encoding, + OUSTRING_TO_OSTRING_CVTFLAGS); + + if (pstr_env_var != 0 && pstr_val != 0) + { +#if defined (SOLARIS) + 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); +#else + if (setenv(rtl_string_getStr(pstr_env_var), rtl_string_getStr(pstr_val), 1) == 0) + result = osl_Process_E_None; +#endif + } + + if (pstr_val) + rtl_string_release(pstr_val); + + if (pstr_env_var != 0) + rtl_string_release(pstr_env_var); + + return (result); +} + +/*************************************** + osl_clearEnvironment(). + **************************************/ +oslProcessError SAL_CALL osl_clearEnvironment(rtl_uString* pustrEnvVar) +{ + oslProcessError result = osl_Process_E_Unknown; + rtl_TextEncoding encoding = osl_getThreadTextEncoding(); + rtl_String* pstr_env_var = 0; + + OSL_PRECOND(pustrEnvVar, "osl_setEnvironment(): Invalid parameter"); + + rtl_uString2String( + &pstr_env_var, + rtl_uString_getStr(pustrEnvVar), rtl_uString_getLength(pustrEnvVar), encoding, + OUSTRING_TO_OSTRING_CVTFLAGS); + + if (pstr_env_var) + { +#if defined (SOLARIS) + 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); +#elif (defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) + //MacOSX baseline is 10.4, which has an old-school void return + //for unsetenv. + //See: http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/10.4/man3/unsetenv.3.html?useVersion=10.4 + unsetenv(rtl_string_getStr(pstr_env_var)); + result = osl_Process_E_None; +#else + if (unsetenv(rtl_string_getStr(pstr_env_var)) == 0) + result = osl_Process_E_None; +#endif + rtl_string_release(pstr_env_var); + } + + return (result); +} + + +/*************************************** osl_getProcessWorkingDir(). **************************************/ oslProcessError SAL_CALL osl_getProcessWorkingDir(rtl_uString **ppustrWorkingDir) diff --git a/sal/osl/w32/process.cxx b/sal/osl/w32/process.cxx index 0fb061b8f..796f4c454 100644 --- a/sal/osl/w32/process.cxx +++ b/sal/osl/w32/process.cxx @@ -414,6 +414,25 @@ oslProcessError SAL_CALL osl_getEnvironment(rtl_uString *ustrVar, rtl_uString ** return osl_Process_E_Unknown; } +oslProcessError SAL_CALL osl_setEnvironment(rtl_uString *ustrVar, rtl_uString *ustrValue) +{ + LPCWSTR lpName = reinterpret_cast<LPCWSTR>(ustrVar->buffer); + LPCWSTR lpValue = reinterpret_cast<LPCWSTR>(ustrValue->buffer); + if (SetEnvironmentVariableW(lpName, lpValue)) + return osl_Process_E_None; + return osl_Process_E_Unknown; +} + +oslProcessError SAL_CALL osl_clearEnvironment(rtl_uString *ustrVar) +{ + //If the second parameter is NULL, the variable is deleted from the current + //process's environment. + LPCWSTR lpName = reinterpret_cast<LPCWSTR>(ustrVar->buffer); + if (SetEnvironmentVariableW(lpName, NULL)) + return osl_Process_E_None; + return osl_Process_E_Unknown; +} + /*************************************************************************** * Current Working Directory. ***************************************************************************/ diff --git a/sal/util/sal.map b/sal/util/sal.map index d5faa563a..8b1c079ec 100755 --- a/sal/util/sal.map +++ b/sal/util/sal.map @@ -597,6 +597,13 @@ UDK_3.10 { # OOo 3.2 rtl_math_acosh; } UDK_3.9; + +UDK_3.11 { # OOo 3.4 + global: + osl_setEnvironment; + osl_clearEnvironment; +} UDK_3.10; + PRIVATE_1.0 { global: osl_detail_ObjectRegistry_storeAddresses; |