Yeah, it seems that MS implemented getenv_s before it was made part of the standard in C11. So I'd lean towards preserving MS-specific semantics.
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm#impementations Best Regards, Luca Inviato da Outlook per Android<https://aka.ms/AAb9ysg> ________________________________ From: Kirill Makurin <[email protected]> Sent: Tuesday, January 13, 2026 10:12:43 PM To: Mingw W64 Public <[email protected]> Cc: Pali Rohár <[email protected]> Subject: Re: [Mingw-w64-public] [RFC] getenv_s is not standard compliant Microsoft documentation[1] does not mention an error condition for getenv_s when environment variable is not found. Also note that we have implementation of getenv_s in: 1. mingw-w64-crt/secapi/getenv_s.c, around CRT's getenv 2. mingw-w64-libraries/winstorecompat/src/getenv_s.c, around GetEnvironmentVariableA both seem to follow Microsoft's behavior when variable is not found. I don't know if anyone really uses these *secure* functions; I would prefer to keep compatibility with Microsoft's implementation. Pali, do you have an opinion on this? [1] https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/getenv-s-wgetenv-s ________________________________ From: Luca Bacci <[email protected]> Sent: Tuesday, January 13, 2026 7:16 PM To: Mingw W64 Public <[email protected]> Subject: [Mingw-w64-public] [RFC] getenv_s is not standard compliant The C standard says (C23 K.3.6.2.1): The getenv_s function returns zero if the specified name is found and the associated string was successfully stored in value . Otherwise, a nonzero value is returned However getenv_s in the UCRT reports success (return value is 0) for non-exisiting environment variables: #include <windows.h> #include <stdlib.h> #include <assert.h> int main (void) { char value[100]; size_t len; errno_t ret; ret = getenv_s (&len, value, sizeof (value), "NONEXISTING"); assert (ret != 0); } Should we provide a wrapper? Best Regards, Luca _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
