cppuhelper/source/servicemanager.cxx             |    7 ++++---
 framework/source/services/substitutepathvars.cxx |    7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

New commits:
commit 0166610b95112b8a6245b2f9ad87001163deeefe
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Mar 30 11:27:05 2025 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Mar 30 13:49:46 2025 +0200

    Use osl_getEnvironment instead of getenv
    
    Avoids conversion to OUString; and is Unicode-safe on Windows.
    
    Change-Id: If4f76f867f988d43ec4dae0a8e09f1390fee42e8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183503
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/cppuhelper/source/servicemanager.cxx 
b/cppuhelper/source/servicemanager.cxx
index 8ace85e1e30b..fbd982923499 100644
--- a/cppuhelper/source/servicemanager.cxx
+++ b/cppuhelper/source/servicemanager.cxx
@@ -42,6 +42,7 @@
 #include <o3tl/safeint.hxx>
 #include <osl/file.hxx>
 #include <osl/module.hxx>
+#include <osl/process.h>
 #include <rtl/ref.hxx>
 #include <rtl/uri.hxx>
 #include <rtl/ustring.hxx>
@@ -1826,10 +1827,10 @@ void 
cppuhelper::ServiceManager::preloadImplementations() {
     OUStringBuffer aMissingMsg;
 
     /// Allow external callers & testers to disable certain components
-    const char *pDisable = getenv("UNODISABLELIBRARY");
-    if (pDisable)
+    if (OUString aDisable;
+        osl_getEnvironment(u"UNODISABLELIBRARY"_ustr.pData, &aDisable.pData) 
== osl_Process_E_None
+        && !aDisable.isEmpty())
     {
-        OUString aDisable(pDisable, strlen(pDisable), RTL_TEXTENCODING_UTF8);
         for (sal_Int32 i = 0; i >= 0; )
         {
             OUString tok( aDisable.getToken(0, ' ', i) );
diff --git a/framework/source/services/substitutepathvars.cxx 
b/framework/source/services/substitutepathvars.cxx
index febece5e6040..b7b65831d82f 100644
--- a/framework/source/services/substitutepathvars.cxx
+++ b/framework/source/services/substitutepathvars.cxx
@@ -26,6 +26,7 @@
 #include <unotools/bootstrap.hxx>
 #include <unotools/configmgr.hxx>
 #include <osl/file.hxx>
+#include <osl/process.h>
 #include <osl/security.hxx>
 #include <osl/thread.hxx>
 #include <i18nlangtag/languagetag.hxx>
@@ -299,13 +300,13 @@ OUString SubstitutePathVariables::GetHomeVariableValue()
 OUString SubstitutePathVariables::GetPathVariableValue()
 {
     OUString aRetStr;
-    const char* pEnv = getenv( "PATH" );
+    OUString aPathList;
 
-    if ( pEnv )
+    if (osl_getEnvironment(u"PATH"_ustr.pData, &aPathList.pData) == 
osl_Process_E_None
+        && !aPathList.isEmpty())
     {
         const int PATH_EXTEND_FACTOR = 200;
         OUString       aTmp;
-        OUString       aPathList( pEnv, strlen( pEnv ), 
osl_getThreadTextEncoding() );
         OUStringBuffer aPathStrBuffer( aPathList.getLength() * 
PATH_EXTEND_FACTOR / 100 );
 
         bool      bAppendSep = false;

Reply via email to