basic/source/runtime/methods1.cxx                         |    5 +--
 cppuhelper/source/servicemanager.cxx                      |    5 +--
 cppuhelper/source/shlib.cxx                               |    6 ++--
 dbaccess/qa/unit/embeddeddb_performancetest.cxx           |    9 +-----
 dbaccess/source/core/dataaccess/datasource.cxx            |    6 +---
 drawinglayer/source/primitive2d/glowprimitive2d.cxx       |    4 +-
 drawinglayer/source/primitive2d/shadowprimitive2d.cxx     |    4 +-
 drawinglayer/source/primitive2d/softedgeprimitive2d.cxx   |    4 +-
 drawinglayer/source/processor2d/SDPRProcessor2dTools.cxx  |    4 +-
 drawinglayer/source/processor2d/vclhelperbufferdevice.cxx |    3 +-
 drawinglayer/source/tools/converters.cxx                  |    7 ++---
 emfio/source/reader/emfreader.cxx                         |    3 +-
 framework/source/services/substitutepathvars.cxx          |    6 ++--
 jvmfwk/plugins/sunmajor/pluginlib/util.cxx                |   11 +++-----
 jvmfwk/source/framework.cxx                               |   16 +++++------
 pyuno/source/loader/pyuno_loader.cxx                      |   15 +++++------
 sal/osl/all/debugbase.cxx                                 |    8 ++---
 sal/osl/w32/procimpl.cxx                                  |    4 +-
 sfx2/source/appl/sfxhelp.cxx                              |    6 +---
 svtools/source/control/inettbc.cxx                        |   19 ++------------
 sw/qa/extras/ooxmlexport/ooxmlexport_de_locale.cxx        |    4 +-
 test/source/screenshot_test.cxx                           |    7 ++---
 test/source/setupvcl.cxx                                  |    7 ++---
 unotest/source/cpp/directories.cxx                        |    6 ++--
 unotest/source/cpp/macros_test.cxx                        |    4 +-
 vcl/source/bitmap/BitmapEx.cxx                            |   11 ++------
 vcl/source/bitmap/bitmap.cxx                              |    3 +-
 xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx    |    6 +---
 xmlsecurity/source/xmlsec/nss/nssinitializer.cxx          |    7 ++---
 29 files changed, 83 insertions(+), 117 deletions(-)

New commits:
commit 3a4961af4356db3949eb7cbbf26342b402be8149
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Jul 16 15:33:46 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Jul 17 07:03:19 2025 +0200

    Use o3tl::{get,set}Environment instead of resp. osl_* functions
    
    Simplifies the code, and avoids OUString internals access.
    Also replace some getenv calls.
    
    Change-Id: I5f7dc492fe87ea1fbaad6a61bc54e21f0f0c5aef
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187974
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/basic/source/runtime/methods1.cxx 
b/basic/source/runtime/methods1.cxx
index e1fd37e45018..0775f6c75bb8 100644
--- a/basic/source/runtime/methods1.cxx
+++ b/basic/source/runtime/methods1.cxx
@@ -35,6 +35,7 @@
 #include <svl/zforlist.hxx>
 #include <tools/urlobj.hxx>
 #include <tools/fract.hxx>
+#include <o3tl/environment.hxx>
 #include <o3tl/temporary.hxx>
 #include <osl/file.hxx>
 #include <osl/process.h>
@@ -1132,9 +1133,7 @@ void SbRtl_Environ(StarBASIC *, SbxArray & rPar, bool)
     if (rPar.Count() != 2)
         return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
 
-    OUString aResult;
-    osl_getEnvironment(rPar.Get(1)->GetOUString().pData, &aResult.pData);
-    rPar.Get(0)->PutString(aResult);
+    rPar.Get(0)->PutString(o3tl::getEnvironment(rPar.Get(1)->GetOUString()));
 }
 
 static double GetDialogZoomFactor( bool bX, tools::Long nValue )
diff --git a/cppuhelper/source/servicemanager.cxx 
b/cppuhelper/source/servicemanager.cxx
index fbd982923499..8e4984228c54 100644
--- a/cppuhelper/source/servicemanager.cxx
+++ b/cppuhelper/source/servicemanager.cxx
@@ -39,6 +39,7 @@
 #include <cppuhelper/implbase.hxx>
 #include <cppuhelper/supportsservice.hxx>
 #include <cppuhelper/factory.hxx>
+#include <o3tl/environment.hxx>
 #include <o3tl/safeint.hxx>
 #include <osl/file.hxx>
 #include <osl/module.hxx>
@@ -1827,9 +1828,7 @@ void cppuhelper::ServiceManager::preloadImplementations() 
{
     OUStringBuffer aMissingMsg;
 
     /// Allow external callers & testers to disable certain components
-    if (OUString aDisable;
-        osl_getEnvironment(u"UNODISABLELIBRARY"_ustr.pData, &aDisable.pData) 
== osl_Process_E_None
-        && !aDisable.isEmpty())
+    if (OUString aDisable = o3tl::getEnvironment(u"UNODISABLELIBRARY"_ustr); 
!aDisable.isEmpty())
     {
         for (sal_Int32 i = 0; i >= 0; )
         {
diff --git a/cppuhelper/source/shlib.cxx b/cppuhelper/source/shlib.cxx
index 2cf101e4d17a..c991ac4d75cf 100644
--- a/cppuhelper/source/shlib.cxx
+++ b/cppuhelper/source/shlib.cxx
@@ -34,6 +34,7 @@
 #include <com/sun/star/registry/XRegistryKey.hpp>
 #include <cppuhelper/factory.hxx>
 #include <cppuhelper/shlib.hxx>
+#include <o3tl/environment.hxx>
 #include <o3tl/string_view.hxx>
 #include <osl/module.hxx>
 #include <osl/process.h>
@@ -52,9 +53,8 @@ css::uno::Environment cppuhelper::detail::getEnvironment(
 {
     OUString n(name);
     if (!implementation.empty()) {
-        OUString imps;
-        if (osl_getEnvironment(u"UNO_ENV_LOG"_ustr.pData, &imps.pData) == 
osl_Process_E_None
-            && !imps.isEmpty()) {
+        OUString imps = o3tl::getEnvironment(u"UNO_ENV_LOG"_ustr);
+        if (!imps.isEmpty()) {
             for (sal_Int32 i = 0; i != -1;) {
                 std::u16string_view imp(o3tl::getToken(imps, 0, ';', i));
                 if (implementation == imp)
diff --git a/dbaccess/qa/unit/embeddeddb_performancetest.cxx 
b/dbaccess/qa/unit/embeddeddb_performancetest.cxx
index d142580f2655..01444e8592f0 100644
--- a/dbaccess/qa/unit/embeddeddb_performancetest.cxx
+++ b/dbaccess/qa/unit/embeddeddb_performancetest.cxx
@@ -10,6 +10,7 @@
 #include "dbtest_base.cxx"
 
 #include <memory>
+#include <o3tl/environment.hxx>
 #include <osl/process.h>
 #include <osl/time.h>
 #include <rtl/ustrbuf.hxx>
@@ -81,9 +82,6 @@ class EmbeddedDBPerformanceTest
     : public DBTestBase
 {
 private:
-    static constexpr OUString our_sEnableTestEnvVar = u"DBA_PERFTEST"_ustr;
-
-
     // We store the results and print them at the end due to the amount of 
warning
     // noise present which otherwise obscures the results.
     OUStringBuffer m_aOutputBuffer;
@@ -143,10 +141,7 @@ void EmbeddedDBPerformanceTest::printTimes(
 
 void EmbeddedDBPerformanceTest::testPerformance()
 {
-    OUString sEnabled;
-    osl_getEnvironment(our_sEnableTestEnvVar.pData, &sEnabled.pData);
-
-    if (sEnabled.isEmpty())
+    if (o3tl::getEnvironment(u"DBA_PERFTEST"_ustr).isEmpty())
         return;
 
     m_aOutputBuffer.append("---------------------
");
diff --git a/dbaccess/source/core/dataaccess/datasource.cxx 
b/dbaccess/source/core/dataaccess/datasource.cxx
index ca2872fbc99c..387b4c88c2a7 100644
--- a/dbaccess/source/core/dataaccess/datasource.cxx
+++ b/dbaccess/source/core/dataaccess/datasource.cxx
@@ -57,6 +57,7 @@
 #include <cppuhelper/typeprovider.hxx>
 #include <officecfg/Office/Common.hxx>
 #include <comphelper/diagnose_ex.hxx>
+#include <o3tl/environment.hxx>
 #include <osl/diagnose.h>
 #include <osl/process.h>
 #include <sal/log.hxx>
@@ -544,10 +545,7 @@ Reference< XConnection > 
ODatabaseSource::buildLowLevelConnection(const OUString
     if(!bIgnoreMigration && m_pImpl->m_sConnectURL == "sdbc:embedded:hsqldb")
     {
         Reference<XStorage> const xRootStorage = 
m_pImpl->getOrCreateRootStorage();
-        OUString sMigrEnvVal;
-        osl_getEnvironment(u"DBACCESS_HSQL_MIGRATION"_ustr.pData,
-            &sMigrEnvVal.pData);
-        if(!sMigrEnvVal.isEmpty())
+        if (!o3tl::getEnvironment(u"DBACCESS_HSQL_MIGRATION"_ustr).isEmpty())
             bNeedMigration = true;
         else
         {
diff --git a/drawinglayer/source/primitive2d/glowprimitive2d.cxx 
b/drawinglayer/source/primitive2d/glowprimitive2d.cxx
index 33a3d59fcc6a..4a4da208e932 100644
--- a/drawinglayer/source/primitive2d/glowprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/glowprimitive2d.cxx
@@ -27,6 +27,7 @@
 #include "GlowSoftEgdeShadowTools.hxx"
 
 #ifdef DBG_UTIL
+#include <o3tl/environment.hxx>
 #include <tools/stream.hxx>
 #include <vcl/filter/PngImageWriter.hxx>
 #endif
@@ -223,8 +224,7 @@ void GlowPrimitive2D::create2DDecomposition(
     if (bDoSaveForVisualControl)
     {
         // VCL_DUMP_BMP_PATH should be like C:/path/ or ~/path/
-        static const OUString sDumpPath(
-            OUString::createFromAscii(std::getenv("VCL_DUMP_BMP_PATH")));
+        static const OUString 
sDumpPath(o3tl::getEnvironment(u"VCL_DUMP_BMP_PATH"_ustr));
         if (!sDumpPath.isEmpty())
         {
             SvFileStream aNew(sDumpPath + "test_glow.png", StreamMode::WRITE | 
StreamMode::TRUNC);
diff --git a/drawinglayer/source/primitive2d/shadowprimitive2d.cxx 
b/drawinglayer/source/primitive2d/shadowprimitive2d.cxx
index 3b932b92f8c5..6c4a0c8121fa 100644
--- a/drawinglayer/source/primitive2d/shadowprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/shadowprimitive2d.cxx
@@ -29,6 +29,7 @@
 #include "GlowSoftEgdeShadowTools.hxx"
 
 #ifdef DBG_UTIL
+#include <o3tl/environment.hxx>
 #include <tools/stream.hxx>
 #include <vcl/filter/PngImageWriter.hxx>
 #endif
@@ -259,8 +260,7 @@ void ShadowPrimitive2D::create2DDecomposition(
     if (bDoSaveForVisualControl)
     {
         // VCL_DUMP_BMP_PATH should be like C:/path/ or ~/path/
-        static const OUString sDumpPath(
-            OUString::createFromAscii(std::getenv("VCL_DUMP_BMP_PATH")));
+        static const OUString 
sDumpPath(o3tl::getEnvironment(u"VCL_DUMP_BMP_PATH"_ustr));
         if (!sDumpPath.isEmpty())
         {
             SvFileStream aNew(sDumpPath + "test_shadowblur.png",
diff --git a/drawinglayer/source/primitive2d/softedgeprimitive2d.cxx 
b/drawinglayer/source/primitive2d/softedgeprimitive2d.cxx
index ed0348e13465..5a34684c7a0c 100644
--- a/drawinglayer/source/primitive2d/softedgeprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/softedgeprimitive2d.cxx
@@ -27,6 +27,7 @@
 #include "GlowSoftEgdeShadowTools.hxx"
 
 #ifdef DBG_UTIL
+#include <o3tl/environment.hxx>
 #include <tools/stream.hxx>
 #include <vcl/filter/PngImageWriter.hxx>
 #endif
@@ -218,8 +219,7 @@ void SoftEdgePrimitive2D::create2DDecomposition(
         if (bDoSaveForVisualControl)
         {
             // VCL_DUMP_BMP_PATH should be like C:/path/ or ~/path/
-            static const OUString sDumpPath(
-                OUString::createFromAscii(std::getenv("VCL_DUMP_BMP_PATH")));
+            static const OUString 
sDumpPath(o3tl::getEnvironment(u"VCL_DUMP_BMP_PATH"_ustr));
             if (!sDumpPath.isEmpty())
             {
                 SvFileStream aNew(sDumpPath + "test_softedge.png",
diff --git a/drawinglayer/source/processor2d/SDPRProcessor2dTools.cxx 
b/drawinglayer/source/processor2d/SDPRProcessor2dTools.cxx
index ae2ddfae81ad..4116c09d6b85 100644
--- a/drawinglayer/source/processor2d/SDPRProcessor2dTools.cxx
+++ b/drawinglayer/source/processor2d/SDPRProcessor2dTools.cxx
@@ -25,6 +25,7 @@
 #include <basegfx/range/b2drange.hxx>
 
 #ifdef DBG_UTIL
+#include <o3tl/environment.hxx>
 #include <tools/stream.hxx>
 #include <vcl/filter/PngImageWriter.hxx>
 #endif
@@ -260,8 +261,7 @@ bool prepareBitmapForDirectRender(
     static bool bDoSaveForVisualControl(false); // loplugin:constvars:ignore
     if (bDoSaveForVisualControl)
     {
-        static const OUString sDumpPath(
-            OUString::createFromAscii(std::getenv("VCL_DUMP_BMP_PATH")));
+        static const OUString 
sDumpPath(o3tl::getEnvironment(u"VCL_DUMP_BMP_PATH"_ustr));
         if (!sDumpPath.isEmpty())
         {
             SvFileStream aNew(sDumpPath + "test_getreplacement.png",
diff --git a/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx 
b/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx
index 6b6499a8b539..eaf717710d6c 100644
--- a/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx
+++ b/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx
@@ -36,6 +36,7 @@
 #include <mutex>
 
 #ifdef DBG_UTIL
+#include <o3tl/environment.hxx>
 #include <tools/stream.hxx>
 #endif
 
@@ -458,7 +459,7 @@ void impBufferDevice::paint(double fTrans)
 #ifdef DBG_UTIL
     // VCL_DUMP_BMP_PATH should be like C:/path/ or ~/path/
     static bool bDoSaveForVisualControl(false); // loplugin:constvars:ignore
-    static const OUString 
sDumpPath(OUString::createFromAscii(std::getenv("VCL_DUMP_BMP_PATH")));
+    static const OUString 
sDumpPath(o3tl::getEnvironment(u"VCL_DUMP_BMP_PATH"_ustr));
 
     if (!sDumpPath.isEmpty() && bDoSaveForVisualControl)
     {
diff --git a/drawinglayer/source/tools/converters.cxx 
b/drawinglayer/source/tools/converters.cxx
index 6d1a87c3e0f3..cd1370140829 100644
--- a/drawinglayer/source/tools/converters.cxx
+++ b/drawinglayer/source/tools/converters.cxx
@@ -32,6 +32,7 @@
 #include <config_vclplug.h>
 
 #ifdef DBG_UTIL
+#include <o3tl/environment.hxx>
 #include <tools/stream.hxx>
 #include <vcl/dibtools.hxx>
 #endif
@@ -250,8 +251,7 @@ BitmapEx 
convertToBitmapEx(drawinglayer::primitive2d::Primitive2DContainer&& rSe
     if (bDoSaveForVisualControl)
     {
         // VCL_DUMP_BMP_PATH should be like C:/path/ or ~/path/
-        static const OUString sDumpPath(
-            OUString::createFromAscii(std::getenv("VCL_DUMP_BMP_PATH")));
+        static const OUString 
sDumpPath(o3tl::getEnvironment(u"VCL_DUMP_BMP_PATH"_ustr));
         if (!sDumpPath.isEmpty())
         {
             SvFileStream aNew(sDumpPath + "test_content.bmp",
@@ -270,8 +270,7 @@ BitmapEx 
convertToBitmapEx(drawinglayer::primitive2d::Primitive2DContainer&& rSe
     if (bDoSaveForVisualControl)
     {
         // VCL_DUMP_BMP_PATH should be like C:/path/ or ~/path/
-        static const OUString sDumpPath(
-            OUString::createFromAscii(std::getenv("VCL_DUMP_BMP_PATH")));
+        static const OUString 
sDumpPath(o3tl::getEnvironment(u"VCL_DUMP_BMP_PATH"_ustr));
         if (!sDumpPath.isEmpty())
         {
             SvFileStream aNew(sDumpPath + "test_alpha.bmp", StreamMode::WRITE 
| StreamMode::TRUNC);
diff --git a/emfio/source/reader/emfreader.cxx 
b/emfio/source/reader/emfreader.cxx
index 31903c4ce10f..abd131bd9072 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -22,6 +22,7 @@
 #include <sal/log.hxx>
 #include <osl/diagnose.h>
 #include <vcl/dibtools.hxx>
+#include <o3tl/environment.hxx>
 #include <o3tl/safeint.hxx>
 #include <o3tl/sprintf.hxx>
 #include <tools/stream.hxx>
@@ -1612,7 +1613,7 @@ namespace emfio
                                     if(bDoSaveForVisualControl)
                                     {
                                         // VCL_DUMP_BMP_PATH should be like 
C:/path/ or ~/path/
-                                        static const OUString 
sDumpPath(OUString::createFromAscii(std::getenv("VCL_DUMP_BMP_PATH")));
+                                        static const OUString 
sDumpPath(o3tl::getEnvironment(u"VCL_DUMP_BMP_PATH"_ustr));
                                         if(!sDumpPath.isEmpty())
                                         {
                                             SvFileStream aNew(sDumpPath + 
"metafile_content.png",
diff --git a/framework/source/services/substitutepathvars.cxx 
b/framework/source/services/substitutepathvars.cxx
index b7b65831d82f..527e7c9fa49d 100644
--- a/framework/source/services/substitutepathvars.cxx
+++ b/framework/source/services/substitutepathvars.cxx
@@ -25,6 +25,7 @@
 
 #include <unotools/bootstrap.hxx>
 #include <unotools/configmgr.hxx>
+#include <o3tl/environment.hxx>
 #include <osl/file.hxx>
 #include <osl/process.h>
 #include <osl/security.hxx>
@@ -300,10 +301,9 @@ OUString SubstitutePathVariables::GetHomeVariableValue()
 OUString SubstitutePathVariables::GetPathVariableValue()
 {
     OUString aRetStr;
-    OUString aPathList;
+    OUString aPathList = o3tl::getEnvironment(u"PATH"_ustr);
 
-    if (osl_getEnvironment(u"PATH"_ustr.pData, &aPathList.pData) == 
osl_Process_E_None
-        && !aPathList.isEmpty())
+    if (!aPathList.isEmpty())
     {
         const int PATH_EXTEND_FACTOR = 200;
         OUString       aTmp;
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx 
b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx
index b6933b2a10b2..a1657ee6ad42 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx
+++ b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx
@@ -29,6 +29,7 @@
 #include <sal/log.hxx>
 #include <salhelper/linkhelper.hxx>
 #include <salhelper/thread.hxx>
+#include <o3tl/environment.hxx>
 #include <o3tl/string_view.hxx>
 #include <memory>
 #include <utility>
@@ -1038,9 +1039,8 @@ void addJavaInfosFromPath(
 {
 #if !defined JVM_ONE_PATH_CHECK
 // Get Java from PATH environment variable
-    OUString usAllPath;
-    if (osl_getEnvironment(u"PATH"_ustr.pData, &usAllPath.pData) != 
osl_Process_E_None
-        || usAllPath.isEmpty())
+    OUString usAllPath = o3tl::getEnvironment(u"PATH"_ustr);
+    if (usAllPath.isEmpty())
         return;
 
     sal_Int32 nIndex = 0;
@@ -1092,9 +1092,8 @@ void addJavaInfoFromJavaHome(
     // variable. We set it in our build environment for build-time programs, 
though,
     // so it is set when running unit tests that involve Java functionality. 
(Which affects
     // at least CppunitTest_dbaccess_dialog_save, too, and not only the 
JunitTest ones.)
-    OUString sHome;
-    if (osl_getEnvironment(u"JAVA_HOME"_ustr.pData, &sHome.pData) == 
osl_Process_E_None
-        && !sHome.isEmpty())
+    OUString sHome = o3tl::getEnvironment(u"JAVA_HOME"_ustr);
+    if (!sHome.isEmpty())
     {
         OUString sHomeUrl;
         if(File::getFileURLFromSystemPath(sHome, sHomeUrl) == File::E_None)
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx
index 0fe6ed7903c4..4c7e4f950ed5 100644
--- a/jvmfwk/source/framework.cxx
+++ b/jvmfwk/source/framework.cxx
@@ -32,6 +32,7 @@
 #include <osl/process.h>
 #endif
 #include <osl/thread.hxx>
+#include <o3tl/environment.hxx>
 #include <o3tl/string_view.hxx>
 #include <jvmfwk/framework.hxx>
 #include <vendorbase.hxx>
@@ -273,15 +274,12 @@ javaFrameworkError jfw_startVM(
         // java.library.path. Somehow setting java.library.path accordingly 
doesn't work,
         // but the PATH gets picked up, so add it there.
         // Without this hack, some features don't work in alternative JREs.
-        OUString sPATH;
-        osl_getEnvironment(OUString("PATH").pData, &sPATH.pData);
-        OUString sJRELocation;
-        osl::FileBase::getSystemPathFromFileURL(pInfo->sLocation + "/bin", 
sJRELocation);
-        if (sPATH.isEmpty())
-            sPATH = sJRELocation;
-        else
-            sPATH = sJRELocation + OUStringChar(SAL_PATHSEPARATOR) + sPATH;
-        osl_setEnvironment(OUString("PATH").pData, sPATH.pData);
+        OUString sOldPATH = o3tl::getEnvironment(u"PATH"_ustr);
+        OUString sNewPATH;
+        osl::FileBase::getSystemPathFromFileURL(pInfo->sLocation + "/bin", 
sNewPATH);
+        if (!sOldPATH.isEmpty())
+            sNewPATH += OUStringChar(SAL_PATHSEPARATOR) + sOldPATH;
+        o3tl::setEnvironment(u"PATH"_ustr, sNewPATH);
 #endif // _WIN32
 
         // create JavaVMOptions array that is passed to the plugin
diff --git a/pyuno/source/loader/pyuno_loader.cxx 
b/pyuno/source/loader/pyuno_loader.cxx
index e1b71af5c360..56a7206d3456 100644
--- a/pyuno/source/loader/pyuno_loader.cxx
+++ b/pyuno/source/loader/pyuno_loader.cxx
@@ -24,6 +24,7 @@
 
 #include <o3tl/any.hxx>
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <o3tl/environment.hxx>
 
 #include <osl/process.h>
 #include <osl/file.hxx>
@@ -179,12 +180,12 @@ static void prependPythonPath( std::u16string_view 
pythonPathBootstrap )
             break;
         nIndex = nNew + 1;
     }
-    const char * oldEnv = getenv( "PYTHONPATH");
-    if( oldEnv )
+    OUString oldEnv = o3tl::getEnvironment(u"PYTHONPATH"_ustr);
+    if (!oldEnv.isEmpty())
     {
         if (bAppendSep)
             bufPYTHONPATH.append( static_cast<sal_Unicode>(SAL_PATHSEPARATOR) 
);
-        bufPYTHONPATH.append( OUString(oldEnv, strlen(oldEnv), 
osl_getThreadTextEncoding()) );
+        bufPYTHONPATH.append(oldEnv);
     }
 
     OUString envVar(u"PYTHONPATH"_ustr);
@@ -229,14 +230,12 @@ void pythonInit() {
 #ifdef _WIN32
     //extend PATH under windows to include the branddir/program so ssl libs 
will be found
     //for use by terminal mailmerge dependency _ssl.pyd
-    OUString sEnvName("PATH");
-    OUString sPath;
-    osl_getEnvironment(sEnvName.pData, &sPath.pData);
+    OUString sPath = o3tl::getEnvironment(u"PATH"_ustr);
     OUString sBrandLocation("$BRAND_BASE_DIR/program");
     rtl::Bootstrap::expandMacros(sBrandLocation);
     osl::FileBase::getSystemPathFromFileURL(sBrandLocation, sBrandLocation);
-    sPath = sPath + OUStringChar(SAL_PATHSEPARATOR) + sBrandLocation;
-    osl_setEnvironment(sEnvName.pData, sPath.pData);
+    sPath += OUStringChar(SAL_PATHSEPARATOR) + sBrandLocation;
+    o3tl::setEnvironment(u"PATH"_ustr, sPath);
 #endif
 
     PyImport_AppendInittab( "pyuno", PyInit_pyuno );
diff --git a/sal/osl/all/debugbase.cxx b/sal/osl/all/debugbase.cxx
index 6f409d21c768..5685d4d5325b 100644
--- a/sal/osl/all/debugbase.cxx
+++ b/sal/osl/all/debugbase.cxx
@@ -22,6 +22,7 @@
 #include <osl/process.h>
 #include <osl/diagnose.hxx>
 #include <sal/log.hxx>
+#include <o3tl/environment.hxx>
 #include <o3tl/string_view.hxx>
 
 #include <algorithm>
@@ -34,12 +35,9 @@ const std::vector<OString>& StaticDebugBaseAddressFilter()
     static const std::vector<OString> theFilter = []()
     {
         std::vector<OString> vec;
-        rtl_uString * pStr = nullptr;
-        if (osl_getEnvironment( u"OSL_DEBUGBASE_STORE_ADDRESSES"_ustr.pData, 
&pStr )
-            == osl_Process_E_None)
+        OUString const 
str(o3tl::getEnvironment(u"OSL_DEBUGBASE_STORE_ADDRESSES"_ustr));
+        if (!str.isEmpty())
         {
-            OUString const str(pStr);
-            rtl_uString_release(pStr);
             sal_Int32 nIndex = 0;
             do {
                 vec.push_back( OUStringToOString(
diff --git a/sal/osl/w32/procimpl.cxx b/sal/osl/w32/procimpl.cxx
index 1af2a45eeaf6..ff60dd06be7e 100644
--- a/sal/osl/w32/procimpl.cxx
+++ b/sal/osl/w32/procimpl.cxx
@@ -32,6 +32,7 @@
 #include <osl/diagnose.h>
 #include <osl/file.hxx>
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <o3tl/environment.hxx>
 
 #include <vector>
 #include <algorithm>
@@ -347,8 +348,7 @@ namespace /* private */
 
     OUString get_batch_processor()
     {
-        OUString comspec;
-        osl_getEnvironment(u"COMSPEC"_ustr.pData, &comspec.pData);
+        OUString comspec = o3tl::getEnvironment(u"COMSPEC"_ustr);
 
         OSL_ASSERT(comspec.getLength());
 
diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx
index 13793dd6e9df..75e9e950a9c0 100644
--- a/sfx2/source/appl/sfxhelp.cxx
+++ b/sfx2/source/appl/sfxhelp.cxx
@@ -52,6 +52,7 @@
 #include <unotools/pathoptions.hxx>
 #include <rtl/byteseq.hxx>
 #include <rtl/ustring.hxx>
+#include <o3tl/environment.hxx>
 #include <o3tl/string_view.hxx>
 #include <officecfg/Office/Common.hxx>
 #include <osl/process.h>
@@ -344,10 +345,7 @@ SfxHelp::SfxHelp()
 {
     // read the environment variable "HELP_DEBUG"
     // if it's set, you will see debug output on active help
-    OUString sHelpDebug;
-    OUString sEnvVarName( u"HELP_DEBUG"_ustr  );
-    osl_getEnvironment( sEnvVarName.pData, &sHelpDebug.pData );
-    bIsDebug = !sHelpDebug.isEmpty();
+    bIsDebug = !o3tl::getEnvironment(u"HELP_DEBUG"_ustr).isEmpty();
 }
 
 SfxHelp::~SfxHelp()
diff --git a/svtools/source/control/inettbc.cxx 
b/svtools/source/control/inettbc.cxx
index 27d423c738ec..bc3cb6ece74b 100644
--- a/svtools/source/control/inettbc.cxx
+++ b/svtools/source/control/inettbc.cxx
@@ -43,6 +43,7 @@
 #include <o3tl/string_view.hxx>
 #include <osl/file.hxx>
 #include <osl/mutex.hxx>
+#include <osl/process.h>
 #include <unotools/historyoptions.hxx>
 #include <unotools/pathoptions.hxx>
 #include <ucbhelper/commandenvironment.hxx>
@@ -653,16 +654,8 @@ void SvtMatchContext_Impl::doExecute()
 /** Parse leading ~ for Unix systems,
     does nothing for Windows
  */
-bool SvtURLBox_Impl::TildeParsing(
-    OUString&
-#ifdef UNX
-    aText
-#endif
-    , OUString&
-#ifdef UNX
-    aBaseURL
-#endif
-)
+bool SvtURLBox_Impl::TildeParsing([[maybe_unused]] OUString& aText,
+                                  [[maybe_unused]] OUString& aBaseURL)
 {
 #ifdef UNX
     if( aText.startsWith( "~" ) )
@@ -673,11 +666,7 @@ bool SvtURLBox_Impl::TildeParsing(
         if( aText.getLength() == 1 || aText[ 1 ] == '/' )
         {
             // covers "~" or "~/..." cases
-            const char* aHomeLocation = getenv( "HOME" );
-            if( !aHomeLocation )
-                aHomeLocation = "";
-
-            aParseTilde = OUString::createFromAscii(aHomeLocation);
+            osl_getEnvironment(u"HOME"_ustr.pData, &aParseTilde.pData);
 
             // in case the whole path is just "~" then there should
             // be no trailing slash at the end
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport_de_locale.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport_de_locale.cxx
index f40100534939..894286dd7d7b 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport_de_locale.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport_de_locale.cxx
@@ -10,6 +10,7 @@
 #include <swmodeltestbase.hxx>
 
 #include <config_folders.h>
+#include <o3tl/environment.hxx>
 #include <osl/process.h>
 #include <osl/file.hxx>
 
@@ -59,8 +60,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf166850_ODT)
     // test ODT import from version 24.2 where this worked
     // but only in the same locale that was used to import from DOCX, not in
     // a different one
-    OUString instdir;
-    osl_getEnvironment(u"INSTDIR"_ustr.pData, &instdir.pData);
+    OUString instdir = o3tl::getEnvironment(u"INSTDIR"_ustr);
     OUString url;
     CPPUNIT_ASSERT_EQUAL(::osl::FileBase::E_None,
                          ::osl::FileBase::getFileURLFromSystemPath(instdir, 
url));
diff --git a/test/source/screenshot_test.cxx b/test/source/screenshot_test.cxx
index 3baad8b24b7a..fc1fb3c39710 100644
--- a/test/source/screenshot_test.cxx
+++ b/test/source/screenshot_test.cxx
@@ -15,6 +15,7 @@
 
 #include <com/sun/star/frame/Desktop.hpp>
 #include <comphelper/processfactory.hxx>
+#include <o3tl/environment.hxx>
 #include <vcl/abstdlg.hxx>
 #include <vcl/filter/PngImageWriter.hxx>
 #include <vcl/svapp.hxx>
@@ -51,12 +52,10 @@ using namespace css::uno;
 constexpr OUString g_aScreenshotDirectory(u"screenshots"_ustr);
 
 ScreenshotTest::ScreenshotTest()
-    : maParent(nullptr, u"vcl/ui/screenshotparent.ui"_ustr, u"ScreenShot"_ustr)
+    : maCurrentLanguage(o3tl::getEnvironment(u"LO_TEST_LOCALE"_ustr))
+    , maParent(nullptr, u"vcl/ui/screenshotparent.ui"_ustr, u"ScreenShot"_ustr)
     , mxParentWidget(maParent.getDialog()->weld_content_area())
 {
-    if (auto const env = getenv("LO_TEST_LOCALE")) {
-        maCurrentLanguage = OUString::fromUtf8(env);
-    }
 }
 
 ScreenshotTest::~ScreenshotTest()
diff --git a/test/source/setupvcl.cxx b/test/source/setupvcl.cxx
index 7e489effb307..d25af59ac28d 100644
--- a/test/source/setupvcl.cxx
+++ b/test/source/setupvcl.cxx
@@ -16,6 +16,7 @@
 #include <comphelper/processfactory.hxx>
 #include <i18nlangtag/languagetag.hxx>
 #include <i18nlangtag/mslangid.hxx>
+#include <o3tl/environment.hxx>
 #include <unotools/configmgr.hxx>
 #include <unotools/syslocaleoptions.hxx>
 #include <vcl/svapp.hxx>
@@ -72,10 +73,8 @@ IMPL_STATIC_LINK_NOARG(Hook, deinitHook, LinkParamNone *, 
void) {
 
 void test::setUpVcl(bool const forceHeadless) {
     // Force locale (and resource files loaded):
-    OUString locale;
-    if (getenv("LO_TEST_LOCALE") != nullptr)
-        locale = OUString::fromUtf8(getenv("LO_TEST_LOCALE"));
-    else
+    OUString locale = o3tl::getEnvironment(u"LO_TEST_LOCALE"_ustr);
+    if (locale.isEmpty())
         locale = "en-US";
 
     SvtSysLocaleOptions localOptions;
diff --git a/unotest/source/cpp/directories.cxx 
b/unotest/source/cpp/directories.cxx
index d4e1f8e1438f..3d6b2593a86e 100644
--- a/unotest/source/cpp/directories.cxx
+++ b/unotest/source/cpp/directories.cxx
@@ -10,8 +10,8 @@
 #include <sal/config.h>
 
 #include <cppunit/TestAssert.h>
+#include <o3tl/environment.hxx>
 #include <osl/file.hxx>
-#include <osl/process.h>
 #include <unotest/directories.hxx>
 
 namespace
@@ -30,10 +30,10 @@ OUString getFileURLFromSystemPath(OUString const& path)
 }
 
 test::Directories::Directories()
+    : m_aSrcRootPath(o3tl::getEnvironment(u"SRC_ROOT"_ustr))
+    , m_aWorkdirRootPath(o3tl::getEnvironment(u"WORKDIR_FOR_BUILD"_ustr))
 {
-    osl_getEnvironment(u"SRC_ROOT"_ustr.pData, &m_aSrcRootPath.pData);
     CPPUNIT_ASSERT_MESSAGE("SRC_ROOT env variable not set", 
!m_aSrcRootPath.isEmpty());
-    osl_getEnvironment(u"WORKDIR_FOR_BUILD"_ustr.pData, 
&m_aWorkdirRootPath.pData);
     CPPUNIT_ASSERT_MESSAGE("WORKDIR_FOR_BUILD env variable not set", 
!m_aWorkdirRootPath.isEmpty());
     m_aSrcRootURL = getFileURLFromSystemPath(m_aSrcRootPath);
     m_aWorkdirRootURL = getFileURLFromSystemPath(m_aWorkdirRootPath);
diff --git a/unotest/source/cpp/macros_test.cxx 
b/unotest/source/cpp/macros_test.cxx
index da25b544b45a..c30eb23b1251 100644
--- a/unotest/source/cpp/macros_test.cxx
+++ b/unotest/source/cpp/macros_test.cxx
@@ -25,6 +25,7 @@
 #include <comphelper/sequence.hxx>
 #include <comphelper/processfactory.hxx>
 #include <unotest/directories.hxx>
+#include <o3tl/environment.hxx>
 #include <osl/file.hxx>
 #include <osl/process.h>
 #include <osl/thread.h>
@@ -213,8 +214,7 @@ extern "C" {
 SAL_DLLPUBLIC_EXPORT
 void test_init_gpg(OUString const& rTargetDir)
 {
-    OUString srcRootPath;
-    osl_getEnvironment(u"SRC_ROOT"_ustr.pData, &srcRootPath.pData);
+    OUString const srcRootPath = o3tl::getEnvironment(u"SRC_ROOT"_ustr);
     if (srcRootPath.isEmpty())
     {
         abort();
diff --git a/vcl/source/bitmap/BitmapEx.cxx b/vcl/source/bitmap/BitmapEx.cxx
index 7244869f7b90..a366541e8da8 100644
--- a/vcl/source/bitmap/BitmapEx.cxx
+++ b/vcl/source/bitmap/BitmapEx.cxx
@@ -20,6 +20,7 @@
 #include <sal/log.hxx>
 #include <rtl/crc.h>
 #include <rtl/math.hxx>
+#include <o3tl/environment.hxx>
 #include <o3tl/underlyingenumvalue.hxx>
 #include <osl/diagnose.h>
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
@@ -1492,18 +1493,14 @@ void  BitmapEx::GetColorModel(css::uno::Sequence< 
sal_Int32 >& rRGBPalette,
 
 void BitmapEx::DumpAsPng(const char* pFileName) const
 {
-    OUString sPath;
+    OUString sPath(u"file:///tmp/bitmap.png"_ustr);
     if (pFileName)
     {
         sPath = OUString::fromUtf8(pFileName);
     }
-    else if (const char* pEnv = std::getenv("VCL_DUMP_BMP_PATH"))
+    else if (OUString env = o3tl::getEnvironment(u"VCL_DUMP_BMP_PATH"_ustr); 
!env.isEmpty())
     {
-        sPath = OUString::fromUtf8(pEnv);
-    }
-    else
-    {
-        sPath = "file:///tmp/bitmap.png";
+        sPath = env;
     }
     SvFileStream aStream(sPath, StreamMode::STD_READWRITE | StreamMode::TRUNC);
     assert(aStream.good());
diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx
index 28b2181201a1..9423d7a70d09 100644
--- a/vcl/source/bitmap/bitmap.cxx
+++ b/vcl/source/bitmap/bitmap.cxx
@@ -52,6 +52,7 @@
 
 #ifdef DBG_UTIL
 #include <cstdlib>
+#include <o3tl/environment.hxx>
 #include <tools/stream.hxx>
 #include <vcl/graphicfilter.hxx>
 #endif
@@ -149,7 +150,7 @@ Bitmap::~Bitmap()
 {
 #ifdef DBG_UTIL
     // VCL_DUMP_BMP_PATH should be like C:/path/ or ~/path/
-    static const OUString 
sDumpPath(OUString::createFromAscii(std::getenv("VCL_DUMP_BMP_PATH")));
+    static const OUString 
sDumpPath(o3tl::getEnvironment(u"VCL_DUMP_BMP_PATH"_ustr));
     // Stepping into the dtor of a bitmap you need, and setting the volatile 
variable to true in
     // debugger, would dump the bitmap in question
     static volatile bool save(false);
diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx 
b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
index 35c8ce97aab5..ef817b3b9cb5 100644
--- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
@@ -39,6 +39,7 @@
 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
 
 #include <osl/file.hxx>
+#include <osl/process.h>
 #include <sal/log.hxx>
 #include <unotools/datetime.hxx>
 
@@ -106,10 +107,7 @@ bool GetPathAllOS(OUString& aPath)
         return false;
     aPath = o3tl::toU(sPath);
 #else
-    const char* cPath = getenv("PATH");
-    if (!cPath)
-        return false;
-    aPath = OUString(cPath, strlen(cPath), osl_getThreadTextEncoding());
+    osl_getEnvironment(u"PATH"_ustr.pData, &aPath.pData);
 #endif
     return (!aPath.isEmpty());
 }
diff --git a/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx 
b/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx
index 23227b49c7a6..f5825ef7834d 100644
--- a/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx
+++ b/xmlsecurity/source/xmlsec/nss/nssinitializer.cxx
@@ -28,6 +28,7 @@
 #include <sal/types.h>
 #include <rtl/bootstrap.hxx>
 #include <rtl/string.hxx>
+#include <o3tl/environment.hxx>
 #include <osl/file.hxx>
 #include <osl/process.h>
 #include <osl/thread.h>
@@ -177,8 +178,7 @@ const OUString & 
ONSSInitializer::getMozillaCurrentProfile(const css::uno::Refer
         m_bIsNSSinitialized = true;
 
     // first, try to get the profile from "MOZILLA_CERTIFICATE_FOLDER"
-    if (OUString pEnv; 
osl_getEnvironment(u"MOZILLA_CERTIFICATE_FOLDER"_ustr.pData, &pEnv.pData) == 
osl_Process_E_None
-                       && !pEnv.isEmpty())
+    if (OUString pEnv = 
o3tl::getEnvironment(u"MOZILLA_CERTIFICATE_FOLDER"_ustr); !pEnv.isEmpty())
     {
         SAL_INFO(
             "xmlsecurity.xmlsec",
@@ -285,8 +285,7 @@ css::uno::Sequence<css::xml::crypto::NSSProfile> SAL_CALL 
ONSSInitializer::getNS
     }
     aProfileList.push_back({u"MANUAL"_ustr, sUserSelect, 
mozilla::MozillaProductType_Default});
 
-    OUString pEnv;
-    osl_getEnvironment(u"MOZILLA_CERTIFICATE_FOLDER"_ustr.pData, &pEnv.pData);
+    OUString pEnv = o3tl::getEnvironment(u"MOZILLA_CERTIFICATE_FOLDER"_ustr);
     aProfileList.push_back({u"MOZILLA_CERTIFICATE_FOLDER"_ustr,
                             pEnv,
                             mozilla::MozillaProductType_Default});

Reply via email to