summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2017-07-30 19:25:17 +1000
committerChris Sherlock <chris.sherlock79@gmail.com>2017-07-30 19:42:38 +1000
commit879d912f7278730664049b26f03481b59a22cc70 (patch)
treec3e940853a8e6705c5e2936daca08f30e75c8ed4
parent633248e240b904352e66c8ff8b23a3b5f2854b69 (diff)
osl: create new function osl_getAllEnvironment()private/tbsdy/osl_getAllEnvironment
Change-Id: Iff2290113696db7e4ce78002701b227cb89b766d
-rw-r--r--include/osl/process.h9
-rw-r--r--include/sal/main.h5
-rw-r--r--sal/osl/unx/process_impl.cxx31
-rw-r--r--sal/osl/w32/process.cxx29
4 files changed, 74 insertions, 0 deletions
diff --git a/include/osl/process.h b/include/osl/process.h
index 3c58419420d0..213e9d47dfd2 100644
--- a/include/osl/process.h
+++ b/include/osl/process.h
@@ -358,13 +358,21 @@ SAL_DLLPUBLIC oslProcessError SAL_CALL osl_getCommandArg(
@param[in] argc The number of elements in the argv array.
@param[in] argv The array of command-line arguments.
+
@see osl_getExecutableFile
@see osl_getCommandArgCount
@see osl_getCommandArg
*/
SAL_DLLPUBLIC void SAL_CALL osl_setCommandArgs (int argc, char **argv);
+/** Get all the environment variables available to the current process.
+
+ @param[out] strVars all environment variables
+*/
+SAL_DLLPUBLIC oslProcessError SAL_CALL osl_getAllEnvironment(rtl_uString **strVars);
+
/** Get the value of one environment variable.
+
@param[in] strVar denotes the name of the variable to get.
@param[out] strValue string that receives the value of environment variable.
*/
@@ -372,6 +380,7 @@ SAL_DLLPUBLIC oslProcessError SAL_CALL osl_getEnvironment(
rtl_uString *strVar, rtl_uString **strValue);
/** Set the value of one environment variable.
+
@param[in] strVar denotes the name of the variable to set.
@param[in] strValue string of the new value of environment variable.
diff --git a/include/sal/main.h b/include/sal/main.h
index 7c79fad5f0f9..b8a0be959c5e 100644
--- a/include/sal/main.h
+++ b/include/sal/main.h
@@ -29,6 +29,11 @@
#include <unistd.h>
#endif
+#ifdef UNX
+#include <unistd.h>
+extern char **environ;
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/sal/osl/unx/process_impl.cxx b/sal/osl/unx/process_impl.cxx
index c38ecedc6491..21fa85dff70a 100644
--- a/sal/osl/unx/process_impl.cxx
+++ b/sal/osl/unx/process_impl.cxx
@@ -44,6 +44,9 @@
#if defined(MACOSX) || defined(IOS)
#include <mach-o/dyld.h>
+#include <unistd.h>
+extern char **environ;
+
namespace {
oslProcessError SAL_CALL bootstrap_getExecutableFile(rtl_uString ** ppFileURL)
@@ -234,6 +237,34 @@ void SAL_CALL osl_setCommandArgs (int argc, char ** argv)
pthread_mutex_unlock (&(g_command_args.m_mutex));
}
+oslProcessError SAL_CALL osl_getAllEnvironment(rtl_uString **ppustrVars)
+{
+ sal_uInt32 countenv=0;
+
+ for (char **env = environ; *env; ++env)
+ countenv++;
+
+ if (ppustrVars)
+ {
+ rtl_uString **temp;
+ for (temp = ppustrVars; *temp; ++temp)
+ rtl_freeMemory(*temp);
+
+ rtl_freeMemory(temp);
+ }
+
+ ppustrVars = static_cast<rtl_uString**>(rtl_allocateMemory(sizeof(rtl_uString*) * countenv));
+
+ for (char **env = environ; *env; ++env, ++ppustrVars)
+ {
+ rtl_uString *pstrTmp = nullptr;
+ rtl_uString_newFromAscii(&pstrTmp, *env);
+ ppustrVars = &pstrTmp;
+ }
+
+ return osl_Process_E_None;
+}
+
oslProcessError SAL_CALL osl_getEnvironment(rtl_uString* pustrEnvVar, rtl_uString** ppustrValue)
{
oslProcessError result = osl_Process_E_NotFound;
diff --git a/sal/osl/w32/process.cxx b/sal/osl/w32/process.cxx
index 758100fc3417..8cb92e9257c3 100644
--- a/sal/osl/w32/process.cxx
+++ b/sal/osl/w32/process.cxx
@@ -448,6 +448,35 @@ void SAL_CALL osl_setCommandArgs (int argc, char ** argv)
#define ENV_BUFFER_SIZE (32*1024-1)
+oslProcessError SAL_CALL osl_getAllEnvironment(rtl_uString **ppustrVars)
+{
+ sal_uInt32 countenv;
+ LPTCH environ = GetEnvironmentStrings();
+
+ for (LPSTR **env = environ; *env; ++env)
+ countenv++;
+
+ if (ppustrVars)
+ {
+ rtl_uString **temp;
+ for (temp = ppustrVars; *temp; ++temp)
+ rtl_freeMemory(*temp);
+
+ rtl_freeMemory(temp);
+ }
+
+ ppustrVars = static_cast<rtl_uString**>(rtl_allocateMemory(sizeof(rtl_uString*) * countenv));
+
+ for (char **env = environ; *env; ++env, ++ppustrVars)
+ {
+ rtl_uString *pstrTmp = nullptr;
+ rtl_uString_newFromAscii(&pstrTmp, *env);
+ ppustrVars = &pstrTmp;
+ }
+ return osl_Process_E_None;
+}
+
+
oslProcessError SAL_CALL osl_getEnvironment(rtl_uString *ustrVar, rtl_uString **ustrValue)
{
WCHAR buff[ENV_BUFFER_SIZE];