Commit eb094728 authored by Andrew Nguyen's avatar Andrew Nguyen Committed by Alexandre Julliard

msvcrt: Initialize _wenviron in Unicode environment getter function.

parent 797d6cb4
...@@ -34,7 +34,7 @@ char * CDECL MSVCRT_getenv(const char *name) ...@@ -34,7 +34,7 @@ char * CDECL MSVCRT_getenv(const char *name)
char **environ; char **environ;
unsigned int length=strlen(name); unsigned int length=strlen(name);
for (environ = *__p__environ(); *environ; environ++) for (environ = MSVCRT__environ; *environ; environ++)
{ {
char *str = *environ; char *str = *environ;
char *pos = strchr(str,'='); char *pos = strchr(str,'=');
...@@ -55,7 +55,11 @@ MSVCRT_wchar_t * CDECL _wgetenv(const MSVCRT_wchar_t *name) ...@@ -55,7 +55,11 @@ MSVCRT_wchar_t * CDECL _wgetenv(const MSVCRT_wchar_t *name)
MSVCRT_wchar_t **environ; MSVCRT_wchar_t **environ;
unsigned int length=strlenW(name); unsigned int length=strlenW(name);
for (environ = *__p__wenviron(); *environ; environ++) /* Initialize the _wenviron array if it's not already created. */
if (!MSVCRT__wenviron)
MSVCRT__wenviron = msvcrt_SnapshotOfEnvironmentW(NULL);
for (environ = MSVCRT__wenviron; *environ; environ++)
{ {
MSVCRT_wchar_t *str = *environ; MSVCRT_wchar_t *str = *environ;
MSVCRT_wchar_t *pos = strchrW(str,'='); MSVCRT_wchar_t *pos = strchrW(str,'=');
......
...@@ -125,6 +125,9 @@ static void test__environ(void) ...@@ -125,6 +125,9 @@ static void test__environ(void)
static void test__wenviron(void) static void test__wenviron(void)
{ {
static const WCHAR cat_eq_dogW[] = {'c','a','t','=','d','o','g',0};
static const WCHAR cat_eqW[] = {'c','a','t','=',0};
int argc; int argc;
char **argv, **envp = NULL; char **argv, **envp = NULL;
WCHAR **wargv, **wenvp = NULL; WCHAR **wargv, **wenvp = NULL;
...@@ -166,6 +169,10 @@ static void test__wenviron(void) ...@@ -166,6 +169,10 @@ static void test__wenviron(void)
/* _wenviron isn't initialized until __wgetmainargs is called or /* _wenviron isn't initialized until __wgetmainargs is called or
* one of the Unicode environment manipulation functions is called. */ * one of the Unicode environment manipulation functions is called. */
ok( _wputenv(cat_eq_dogW) == 0, "failed setting cat=dog\n" );
ok( *p_wenviron != NULL, "Expected _wenviron to be non-NULL\n" );
ok( _wputenv(cat_eqW) == 0, "failed deleting cat\n" );
__wgetmainargs(&argc, &wargv, &wenvp, 0, &mode); __wgetmainargs(&argc, &wargv, &wenvp, 0, &mode);
ok( *p_wenviron != NULL, "Expected _wenviron to be non-NULL\n" ); ok( *p_wenviron != NULL, "Expected _wenviron to be non-NULL\n" );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment