On 24.04.2020 14:35, Steve Lhomme wrote:
On 2020-04-24 14:30, Jacek Caban wrote:
On 24.04.2020 14:26, Steve Lhomme wrote:
On 2020-04-24 14:24, Jacek Caban wrote:
On 24.04.2020 13:43, Steve Lhomme wrote:
This avoids relying on getenv() from winstorecompat that returns NULL and can't
be reimplemented in a clean way.


What's the problem with getenv()? Would using _wgetenv instead help?

According to this page it's not allowed
https://docs.microsoft.com/en-us/cpp/cppcx/crt-functions-not-supported-in-universal-windows-platform-apps


OK. You could use GetEnvironmentVariableW and pass NULL buffer if you're only interested in checking if the variable exists.

Why GetEnvironmentVariableW and not GetEnvironmentVariableA ? The ANSI version is available in win8 UWP so we don't need the extra size.


We don't need extra size and avoid useless conversion, see bellow.



The documentation doesn't mention if NULL is allowed and 0 may just give an error because the the null-terminating character is supposed to be there.

https://docs.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-getenvironmentvariablew



From this page: "If /lpBuffer/ is not large enough to hold the data, the return value is the buffer size, in characters, required to hold the string and its terminating null character and the contents of /lpBuffer/ are undefined." It means that if you pass 0-size buffer, it will return the size of required buffer. You could just do GetEnvironmentVariableW(L"POSIXLY_CORRECT", NULL, 0) != 0;


Jacek



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to