From 0166610b95112b8a6245b2f9ad87001163deeefe Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 30 Mar 2025 11:27:05 +0100 Subject: [PATCH] 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 Tested-by: Jenkins --- cppuhelper/source/servicemanager.cxx | 7 ++++--- framework/source/services/substitutepathvars.cxx | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) 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 #include #include +#include #include #include #include @@ -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 #include #include +#include #include #include #include @@ -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;