Search code examples
cwindowsenvironment-variables

Is environ available on Windows?


Is environ variable (as of POSIX) available (at least for reading) in major Windows C compilers?

I know that execve is available on Windows: https://en.wikipedia.org/wiki/Exec_(system_call)

But I am unsure if environ is available, too.


Solution

  • environ should be available, but is deprecated and you should use the more secure methods.

    The execXX() calls are available, but fork() isn't, so effectively the exec functions are rendered useless.

    You can use CreateProcessA for similar effect, and have the ability to set up environments and pipes cleanly.

    Just to acknowledge @eryksun 's concerns: You do need to consider which character set you are using before using any Microsoft "A" file (and other O/S) APIs. It is simplest if you can do all your code using 16bit unicode, as that is the underlying type for NT, Windows 7, Windows 10. On unix and mac, you can make assumptions that utf-8 is the 8-bit character set of choice, but that has yet to happen for windows, and of course "backward compatibility". If you are using any of the "unix-like" M/S API, you should already be making the same design decisions, though, so should already have an answer.