implement our own setenv function on Windows

do not rely on _putenv_s to be available on all Windows versions.
ensure 0-termination of string in snprintf even on windows.