Andrew Nguyen : msvcrt: Initialize _wenviron in Unicode environment getter function.
Alexandre Julliard
julliard at winehq.org
Thu Oct 7 11:24:25 CDT 2010
Module: wine
Branch: master
Commit: eb094728709b08f42a3db13074a6105120da24cb
URL: http://source.winehq.org/git/wine.git/?a=commit;h=eb094728709b08f42a3db13074a6105120da24cb
Author: Andrew Nguyen <anguyen at codeweavers.com>
Date: Wed Oct 6 21:59:57 2010 -0500
msvcrt: Initialize _wenviron in Unicode environment getter function.
---
dlls/msvcrt/environ.c | 8 ++++++--
dlls/msvcrt/tests/environ.c | 7 +++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcrt/environ.c b/dlls/msvcrt/environ.c
index 6ceeebb..add5905 100644
--- a/dlls/msvcrt/environ.c
+++ b/dlls/msvcrt/environ.c
@@ -34,7 +34,7 @@ char * CDECL MSVCRT_getenv(const char *name)
char **environ;
unsigned int length=strlen(name);
- for (environ = *__p__environ(); *environ; environ++)
+ for (environ = MSVCRT__environ; *environ; environ++)
{
char *str = *environ;
char *pos = strchr(str,'=');
@@ -55,7 +55,11 @@ MSVCRT_wchar_t * CDECL _wgetenv(const MSVCRT_wchar_t *name)
MSVCRT_wchar_t **environ;
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 *pos = strchrW(str,'=');
diff --git a/dlls/msvcrt/tests/environ.c b/dlls/msvcrt/tests/environ.c
index 2e3e7f8..9e1263a 100644
--- a/dlls/msvcrt/tests/environ.c
+++ b/dlls/msvcrt/tests/environ.c
@@ -125,6 +125,9 @@ static void test__environ(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;
char **argv, **envp = NULL;
WCHAR **wargv, **wenvp = NULL;
@@ -166,6 +169,10 @@ static void test__wenviron(void)
/* _wenviron isn't initialized until __wgetmainargs is called or
* 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);
ok( *p_wenviron != NULL, "Expected _wenviron to be non-NULL\n" );
More information about the wine-cvs
mailing list