diff options
-rw-r--r-- | compat/mingw.c | 15 | ||||
-rw-r--r-- | compat/mingw.h | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c index c725a3e206..cb0914af6c 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1260,6 +1260,12 @@ char *mingw_getenv(const char *name) return result; } +int mingw_putenv(const char *namevalue) +{ + environ = env_setenv(environ, namevalue); + return 0; +} + /* * Note, this isn't a complete replacement for getaddrinfo. It assumes * that service contains a numerical port, or that it is null. It @@ -2052,6 +2058,11 @@ void mingw_startup() maxlen = wcslen(_wpgmptr); for (i = 1; i < argc; i++) maxlen = max(maxlen, wcslen(wargv[i])); + for (i = 0; wenv[i]; i++) + maxlen = max(maxlen, wcslen(wenv[i])); + + /* nedmalloc can't free CRT memory, allocate resizable environment list */ + environ = xcalloc(i + 1, sizeof(char*)); /* allocate buffer (wchar_t encodes to max 3 UTF-8 bytes) */ maxlen = 3 * maxlen + 1; @@ -2064,6 +2075,10 @@ void mingw_startup() len = xwcstoutf(buffer, wargv[i], maxlen); __argv[i] = xmemdupz(buffer, len); } + for (i = 0; wenv[i]; i++) { + len = xwcstoutf(buffer, wenv[i], maxlen); + environ[i] = xmemdupz(buffer, len); + } free(buffer); /* initialize critical section for waitpid pinfo_t list */ diff --git a/compat/mingw.h b/compat/mingw.h index 405c08fcc3..ca80be1bbe 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -207,6 +207,8 @@ char *mingw_getcwd(char *pointer, int len); char *mingw_getenv(const char *name); #define getenv mingw_getenv +int mingw_putenv(const char *namevalue); +#define putenv mingw_putenv int mingw_gethostname(char *host, int namelen); #define gethostname mingw_gethostname |