C++ Logo

sg16

Advanced search

Re: [isocpp-lib-ext] std::environment

From: Thiago Macieira <thiago_at_[hidden]>
Date: Thu, 05 Jan 2023 00:17:56 -0300
On Monday, 2 January 2023 07:22:17 -03 Corentin Jabot via SG16 wrote:
> There are 2 features here:
> * The ability to set environment variables on a child process ( in
> effect a fancy range of pair of string that can be seeded by the
> environment of the current process )
> * The ability to query the environment

Indeed and this also matches how Qt does it.

Ville linked to the functions that query the current state. The other portion
of it is QProcessEnvironment
https://doc.qt.io/qt-6/qprocessenvironment.html

As the name says, it's designed for use with QProcess, though you can query
the current environment with it. You can build it up from empty or you can
request a snapshot of the system environment at the time of the call. From
that point onwards, there's no thread-safety issue.

This solves two of the three biggest cases of environment variables.

The third is modifying the current process' environment. Even though that
changes what child processes will see, it's not usually the objective.
Instead, putenv() is often done to communicate with another portion of the
same process for which there's no direct API. If that's so, I would say we
don't need to satisfy it now.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-01-05 03:18:54