ReactOS 0.4.16-dev-1056-gbe87e00
environ.c File Reference
#include "wine/test.h"
#include <errno.h>
#include <stdlib.h>
#include <process.h>
#include <winnls.h>
Include dependency graph for environ.c:

Go to the source code of this file.

Functions

static char ***__cdeclp__p__environ (void)
 
static WCHAR ***__cdeclp__p__wenviron (void)
 
static char ***__cdeclp__p___initenv (void)
 
static wchar_t ***__cdeclp__p___winitenv (void)
 
static void (__cdecl *p_get_environ)(char ***)
 
static errno_t (__cdecl *p_putenv_s)(const char *
 
static void init (void)
 
static void test_system (void)
 
static unsigned env_get_entry_countA (char **env)
 
static wchar_tenv_get_valueW (wchar_t **envp, const wchar_t *var)
 
static void test__environ (void)
 
static void test__wenviron (void)
 
static void test_environment_manipulation (void)
 
static void test_child_env (char **argv)
 
static void test_case_insensitive (void)
 
 START_TEST (environ)
 

Variables

static const chara_very_long_env_string
 
static const char *static const wchar_t *static char size_t
 
static const char *static const wchar_t *static char const char *static char *** p_environ
 
static WCHAR *** p_wenviron
 

Function Documentation

◆ env_get_entry_countA()

static unsigned env_get_entry_countA ( char **  env)
static

Definition at line 92 of file environ.c.

93{
94 unsigned count;
95
96 if (!env) return 0;
97 for (count = 0; env[count] != NULL; count++) {}
98 return count;
99}
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:170
#define NULL
Definition: types.h:112
GLuint GLuint GLsizei count
Definition: gl.h:1545

Referenced by test_environment_manipulation().

◆ env_get_valueW()

static wchar_t * env_get_valueW ( wchar_t **  envp,
const wchar_t var 
)
static

Definition at line 101 of file environ.c.

102{
103 unsigned i;
104 size_t len = wcslen( var );
105
106 if (!envp) return NULL;
107 for (i = 0; envp[i] != NULL; i++)
108 {
109 wchar_t *ptr;
110
111 if (!(ptr = wcschr( envp[i], L'=' ))) continue;
112
113 if (ptr - envp[i] == len && !memcmp( envp[i], var, len * sizeof(wchar_t) ))
114 return ptr + 1;
115 }
116 return NULL;
117}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define wcschr
Definition: compat.h:17
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static PVOID ptr
Definition: dispmode.c:27
const char * var
Definition: shader.c:5666
#define L(x)
Definition: ntvdm.h:50

Referenced by test__wenviron().

◆ errno_t()

static errno_t ( __cdecl p_putenv_s) const
static

◆ init()

static void init ( void  )
static

Definition at line 66 of file environ.c.

67{
68 HMODULE hmod = GetModuleHandleA("msvcrt.dll");
69
70 p__p__environ = (void *)GetProcAddress(hmod, "__p__environ");
71 p__p__wenviron = (void *)GetProcAddress(hmod, "__p__wenviron");
72 p__p___initenv = (void *)GetProcAddress(hmod, "__p___initenv");
73 p__p___winitenv = (void *)GetProcAddress(hmod, "__p___winitenv");
74 p_environ = (void *)GetProcAddress(hmod, "_environ");
75 p_wenviron = (void *)GetProcAddress(hmod, "_wenviron");
76 p_get_environ = (void *)GetProcAddress(hmod, "_get_environ");
77 p_get_wenviron = (void *)GetProcAddress(hmod, "_get_wenviron");
78 p_putenv_s = (void *)GetProcAddress(hmod, "_putenv_s");
79 p_wputenv_s = (void *)GetProcAddress(hmod, "_wputenv_s");
80 p_getenv_s = (void *)GetProcAddress(hmod, "getenv_s");
81}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:143
static char ***__cdecl * p__p___initenv(void)
static const char *static const wchar_t *static char const char *static char *** p_environ
Definition: environ.c:63
static WCHAR ***__cdecl * p__p__wenviron(void)
static char ***__cdecl * p__p__environ(void)
static wchar_t ***__cdecl * p__p___winitenv(void)
static WCHAR *** p_wenviron
Definition: environ.c:64

Referenced by START_TEST().

◆ p__p___initenv()

static char ***__cdecl * p__p___initenv ( void  )
static

Referenced by init(), and test__environ().

◆ p__p___winitenv()

static wchar_t ***__cdecl * p__p___winitenv ( void  )
static

Referenced by init(), and test__wenviron().

◆ p__p__environ()

static char ***__cdecl * p__p__environ ( void  )
static

◆ p__p__wenviron()

static WCHAR ***__cdecl * p__p__wenviron ( void  )
static

◆ START_TEST()

START_TEST ( environ  )

Definition at line 452 of file environ.c.

453{
454 char **argv;
455 int argc;
456
457 init();
458
460 if (argc == 3 && !strcmp( argv[2], "create" ))
461 {
462 ok( getenv( "__winetest_dog" ) && !strcmp( getenv( "__winetest_dog" ), "bark" ),
463 "Couldn't find env var\n" );
464 skip_2k3_fail ok( _wgetenv( L"__winetest_\u263a" ) && !wcscmp( _wgetenv( L"__winetest_\u263a" ), L"\u03b2" ),
465 "Couldn't find unicode env var\n" );
466 return;
467 }
468
473 test_system();
475}
static int argc
Definition: ServiceArgs.c:12
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ok(value,...)
Definition: atltest.h:57
_Check_return_ _CRTIMP wchar_t *__cdecl _wgetenv(_In_z_ const wchar_t *_VarName)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
static void test__environ(void)
Definition: environ.c:119
static void init(void)
Definition: environ.c:66
static void test_case_insensitive(void)
Definition: environ.c:429
static void test__wenviron(void)
Definition: environ.c:175
static void test_environment_manipulation(void)
Definition: environ.c:263
static void test_child_env(char **argv)
Definition: environ.c:394
static void test_system(void)
Definition: environ.c:83
#define argv
Definition: mplay32.c:18
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
int winetest_get_mainargs(char ***pargv)
#define skip_2k3_fail
Definition: test.h:191

◆ test__environ()

static void test__environ ( void  )
static

Definition at line 119 of file environ.c.

120{
121 int argc;
122 char **argv, **envp = NULL, **initenv = NULL;
123 int mode = 0;
124
125 ok( p_environ != NULL, "Expected the pointer to _environ to be non-NULL\n" );
126 ok( *p_environ != NULL, "Expected _environ to be initialized on startup\n" );
127
128 if (sizeof(void*) != sizeof(int))
129 ok( !p__p__environ, "__p__environ() should be 32-bit only\n");
130 else
131 ok( *p__p__environ() == *p_environ, "Expected _environ pointers to be identical\n" );
132
133 if (p_get_environ)
134 {
135 char **retptr;
136 p_get_environ(&retptr);
137 ok( retptr == *p_environ,
138 "Expected _environ pointers to be identical\n" );
139 }
140 else
141 win_skip( "_get_environ() is not available\n" );
142
143 if (p__p___initenv)
144 {
145 initenv = *p__p___initenv();
146
147 ok( initenv == *p_environ,
148 "Expected _environ to be equal to initial env\n" );
149 }
150 else
151 skip( "__p___initenv() is not available\n" );
152
153 /* Note that msvcrt from Windows versions older than Vista
154 * expects the mode pointer parameter to be valid.*/
155 __getmainargs(&argc, &argv, &envp, 0, &mode);
156
157 ok( envp != NULL,
158 "Expected initial environment block pointer to be non-NULL\n" );
159 ok( envp == *p_environ,
160 "Expected initial environment to be equal to _environ\n" );
161
162 ok( _putenv("cat=dog") == 0, "failed setting cat=dog\n" );
163 if (p__p___initenv)
164 {
165 char **retptr = *p__p___initenv();
166
167 ok( retptr != *p_environ,
168 "Expected _environ[] not to be equal to initial env\n" );
169 ok( retptr == initenv,
170 "Unexpected modification of initial env\n" );
171 }
172 ok( _putenv("cat=") == 0, "failed setting cat=\n" );
173}
#define skip(...)
Definition: atltest.h:64
void __getmainargs(int *argc, char ***argv, char ***envp, int expand_wildcards, int *new_mode)
Definition: getargs.c:182
GLenum mode
Definition: glext.h:6217
_Check_return_ _CRTIMP int __cdecl _putenv(_In_z_ const char *_EnvString)
#define win_skip
Definition: test.h:164

Referenced by START_TEST().

◆ test__wenviron()

static void test__wenviron ( void  )
static

Definition at line 175 of file environ.c.

176{
177 int argc;
178 char **argv, **envp = NULL;
179 WCHAR **wargv, **wenvp = NULL;
180 int mode = 0;
181
182 ok( p_wenviron != NULL, "Expected the pointer to _wenviron to be non-NULL\n" );
183 ok( !*p_wenviron, "Expected _wenviron[] to be NULL, got %p\n", *p_wenviron );
184
185 if (sizeof(void*) != sizeof(int))
186 ok( !p__p__wenviron, "__p__wenviron() should be 32-bit only\n");
187 else
188 ok( !*p__p__wenviron(), "Expected _wenviron to be NULL, got %p\n", *p_wenviron );
189
190 if (p_get_wenviron)
191 {
192 WCHAR **retptr;
193 p_get_wenviron(&retptr);
194 ok( retptr == *p_wenviron, "Expected _wenviron pointers to be NULL\n" );
195 }
196 else
197 win_skip( "_get_wenviron() is not available\n" );
198
199 if (p__p___winitenv)
200 {
201 wchar_t ***retptr = p__p___winitenv();
202 ok( !*retptr, "Expected initial env to be NULL\n" );
203 }
204 else
205 skip( "__p___winitenv() is not available\n" );
206
207 /* __getmainargs doesn't initialize _wenviron. */
208 __getmainargs(&argc, &argv, &envp, 0, &mode);
209
210 ok( !*p_wenviron, "Expected _wenviron to be NULL\n");
211 ok( envp != NULL, "Expected initial environment block pointer to be non-NULL\n" );
212 if (!envp)
213 {
214 skip( "Initial environment block pointer is not valid\n" );
215 return;
216 }
217
218 /* Neither does calling the non-Unicode environment manipulation functions. */
219 ok( _putenv("cat=dog") == 0, "failed setting cat=dog\n" );
220 ok( !*p_wenviron, "Expected _wenviron to be NULL\n" );
221
222 /* _wenviron isn't initialized until __wgetmainargs is called or
223 * one of the Unicode environment manipulation functions is called. */
224 ok( _wputenv(L"cat=dog2") == 0, "failed setting cat=dog2\n" );
225 ok( *p_wenviron != NULL, "Expected _wenviron to be non-NULL\n" );
226
227 __wgetmainargs(&argc, &wargv, &wenvp, 0, &mode);
228 ok( wenvp != NULL, "Expected initial environment block pointer to be non-NULL\n" );
229 ok( wenvp == *p_wenviron, "Expected initial environment to be _wenviron[]\n" );
230
231 if (p__p___winitenv)
232 {
233 wchar_t ***retptr = p__p___winitenv();
234 wchar_t *value;
235
236 skip_2k3_fail ok( *retptr != NULL, "Expected *__p___winitenv() to be NULL\n" );
237 ok( *retptr != *p_wenviron,
238 "Expected _wenviron to be different from __p___winitenv() %p %p\n", *retptr, *p_wenviron );
239 /* test that w-initial env is derived from current _environ[] and not from ansi initial env */
240 value = env_get_valueW( *retptr, L"cat" );
241 skip_2k3_fail ok( value && !wcscmp( value, L"dog" ),
242 "Expecting initial env to be derived from current env (got %ls)\n", value );
243 }
244 _putenv("cat=");
245
246 /* Examine the returned pointer from __p__wenviron(),
247 * if available, after _wenviron is initialized. */
248 if (p__p__wenviron)
249 {
251 "Expected _wenviron pointers to be identical\n" );
252 }
253
254 if (p_get_wenviron)
255 {
256 WCHAR **retptr;
257 p_get_wenviron(&retptr);
258 ok( retptr == *p_wenviron,
259 "Expected _wenviron pointers to be identical\n" );
260 }
261}
_Check_return_ _CRTIMP int __cdecl _wputenv(_In_z_ const wchar_t *_EnvString)
static wchar_t * env_get_valueW(wchar_t **envp, const wchar_t *var)
Definition: environ.c:101
void CDECL __wgetmainargs(int *argc, WCHAR ***wargv, WCHAR ***wenvp, int expand_wildcards, int *new_mode)
Definition: pdh_main.c:96
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ test_case_insensitive()

static void test_case_insensitive ( void  )
static

Definition at line 429 of file environ.c.

430{
431 const char *uppercase_env = getenv("APPDATA");
432 const char *lowercase_env = getenv("appdata");
433 const wchar_t *uppercase_wenv = _wgetenv(L"APPDATA");
434 const wchar_t *lowercase_wenv = _wgetenv(L"appdata");
435
436 ok( uppercase_env == lowercase_env, "getenv() must be case insensitive, %p should be %p\n",
437 lowercase_env, uppercase_env );
438 ok( uppercase_wenv == lowercase_wenv, "_wgetenv() must be case insensitive, %p should be %p\n",
439 lowercase_wenv, uppercase_wenv );
440
441 ok( !_putenv("cAt=bar"), "Failed to set CAT=bar\n" );
442 ok( !_putenv("CAT=BAR"), "Failed to set CAT=BAR\n" );
443 ok( !strcmp(getenv("cAt"), "BAR"), "_putenv() must be case insensitive\n" );
444
445 ok( !_wputenv(L"cAt=bar"), "Failed to set CAT=bar\n" );
446 ok( !_wputenv(L"CAT=BAR"), "Failed to set CAT=BAR\n" );
447 ok( !wcscmp(_wgetenv(L"cAt"), L"BAR"), "_wputenv() must be case insensitive\n" );
448
449 _putenv("cat=");
450}

Referenced by START_TEST().

◆ test_child_env()

static void test_child_env ( char **  argv)
static

Definition at line 394 of file environ.c.

395{
396 STARTUPINFOA si = {sizeof(si)};
397 WCHAR *cur_env, *env, *p, *q;
399 char tmp[1024];
400 BOOL ret;
401 int len;
402
403 cur_env = GetEnvironmentStringsW();
404 ok( cur_env != NULL, "GetEnvironemntStrings failed\n" );
405
406 p = cur_env;
407 while (*p) p += wcslen( p ) + 1;
408 len = p - cur_env;
409 env = malloc( (len + 1024) * sizeof(*env) );
410 memcpy(env, cur_env, len * sizeof(*env) );
411 q = env + len;
412 FreeEnvironmentStringsW( cur_env );
413
414 wcscpy( q, L"__winetest_dog=bark" );
415 q += wcslen( L"__winetest_dog=bark" ) + 1;
416 wcscpy( q, L"__winetest_\u263a=\u03b2" );
417 q += wcslen( L"__winetest_\u263a=\u03b2" ) + 1;
418 *q = 0;
419
420 snprintf( tmp, sizeof(tmp), "%s %s create", argv[0], argv[1] );
422 ok( ret, "Couldn't create child process %s\n", tmp );
424 CloseHandle( pi.hProcess );
425 CloseHandle( pi.hThread );
426 free( env );
427}
wcscpy
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
BOOL WINAPI FreeEnvironmentStringsW(IN LPWSTR EnvironmentStrings)
Definition: environ.c:389
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4747
unsigned int BOOL
Definition: ntddk_ex.h:94
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static refpint_t pi[]
Definition: server.c:96
void winetest_wait_child_process(HANDLE process)
int ret
#define CREATE_UNICODE_ENVIRONMENT
Definition: winbase.h:189
LPWSTR WINAPI GetEnvironmentStringsW(void)
Definition: environ.c:344
#define snprintf
Definition: wintirpc.h:48

Referenced by START_TEST().

◆ test_environment_manipulation()

static void test_environment_manipulation ( void  )
static

Definition at line 263 of file environ.c.

264{
265 char buf[256];
266 errno_t ret;
267 size_t len;
268 unsigned count;
269 char* first;
270 char* second;
271
272 ok( _putenv("cat=") == 0, "_putenv failed on deletion of nonexistent environment variable\n" );
273 ok( _putenv("cat=dog") == 0, "failed setting cat=dog\n" );
274 ok( strcmp(getenv("cat"), "dog") == 0, "getenv did not return 'dog'\n" );
275 if (p_getenv_s)
276 {
277 ret = p_getenv_s(&len, buf, sizeof(buf), "cat");
278 ok( !ret, "getenv_s returned %d\n", ret );
279 ok( len == 4, "getenv_s returned length is %Id\n", len);
280 ok( !strcmp(buf, "dog"), "getenv_s did not return 'dog'\n");
281 }
282 ok( _putenv("cat=") == 0, "failed deleting cat\n" );
283
284 ok( _putenv("=") == -1, "should not accept '=' as input\n" );
285 ok( _putenv("=dog") == -1, "should not accept '=dog' as input\n" );
286 ok( _putenv(a_very_long_env_string) == 0, "_putenv failed for long environment string\n");
287
288 ok( getenv("nonexistent") == NULL, "getenv should fail with nonexistent var name\n" );
289
290 if (p_putenv_s)
291 {
292 ret = p_putenv_s(NULL, "dog");
293 ok( ret == EINVAL, "_putenv_s returned %d\n", ret);
294 ret = p_putenv_s("cat", NULL);
295 ok( ret == EINVAL, "_putenv_s returned %d\n", ret);
296 ret = p_putenv_s("a=b", NULL);
297 ok( ret == EINVAL, "_putenv_s returned %d\n", ret);
298 ret = p_putenv_s("cat", "a=b");
299 ok( !ret, "_putenv_s returned %d\n", ret);
300 ret = p_putenv_s("cat", "");
301 ok( !ret, "_putenv_s returned %d\n", ret);
302 }
303
304 if (p_wputenv_s)
305 {
306 ret = p_wputenv_s(NULL, L"dog");
307 ok( ret == EINVAL, "_wputenv_s returned %d\n", ret);
308 ret = p_wputenv_s(L"cat", NULL);
309 ok( ret == EINVAL, "_wputenv_s returned %d\n", ret);
310 ret = p_wputenv_s(L"a=b", NULL);
311 ok( ret == EINVAL, "_wputenv_s returned %d\n", ret);
312 ret = p_wputenv_s(L"cat", L"a=b");
313 ok( !ret, "_wputenv_s returned %d\n", ret);
314 ret = p_wputenv_s(L"cat", L"");
315 ok( !ret, "_wputenv_s returned %d\n", ret);
316 }
317
318 if (p_getenv_s)
319 {
320 buf[0] = 'x';
321 len = 1;
322 errno = 0xdeadbeef;
323 ret = p_getenv_s(&len, buf, sizeof(buf), "nonexistent");
324 ok( !ret, "_getenv_s returned %d\n", ret);
325 ok( !len, "getenv_s returned length is %Id\n", len);
326 ok( !buf[0], "buf = %s\n", buf);
327 ok( errno == 0xdeadbeef, "errno = %d\n", errno);
328
329 buf[0] = 'x';
330 len = 1;
331 errno = 0xdeadbeef;
332 ret = p_getenv_s(&len, buf, sizeof(buf), NULL);
333 ok( !ret, "_getenv_s returned %d\n", ret);
334 ok( !len, "getenv_s returned length is %Id\n", len);
335 ok( !buf[0], "buf = %s\n", buf);
336 ok( errno == 0xdeadbeef, "errno = %d\n", errno);
337 }
338
339 /* test stability of _environ[] pointers */
340 ok( _putenv( "__winetest_cat=" ) == 0, "Couldn't reset env var\n" );
341 ok( _putenv( "__winetest_dog=" ) == 0, "Couldn't reset env var\n" );
343 ok( _putenv( "__winetest_cat=mew") == 0, "Couldn't set env var\n" );
344 ok( !strcmp( (*p_environ)[count], "__winetest_cat=mew"), "Unexpected env var value\n" );
345 first = (*p_environ)[count];
346 ok( getenv("__winetest_cat") == strchr( (*p_environ)[count], '=') + 1, "Expected getenv() to return pointer inside _environ[] entry\n" );
347 ok( _putenv( "__winetest_dog=bark" ) == 0, "Couldn't set env var\n" );
348 ok( !strcmp( (*p_environ)[count + 1], "__winetest_dog=bark" ), "Unexpected env var value\n" );
349 ok( getenv( "__winetest_dog" ) == strchr( (*p_environ)[count + 1], '=' ) + 1, "Expected getenv() to return pointer inside _environ[] entry\n" );
350 ok( first == (*p_environ)[count], "Expected stability of _environ[count] pointer\n" );
351 second = (*p_environ)[count + 1];
352 ok( count + 2 == env_get_entry_countA( *p_environ ), "Unexpected count\n" );
353
354 ok( _putenv( "__winetest_cat=purr" ) == 0, "Couldn't set env var\n" );
355 ok( !strcmp( (*p_environ)[count], "__winetest_cat=purr" ), "Unexpected env var value\n" );
356 ok( getenv( "__winetest_cat" ) == strchr( (*p_environ)[count], '=' ) + 1, "Expected getenv() to return pointer inside _environ[] entry\n" );
357 ok( second == (*p_environ)[count + 1], "Expected stability of _environ[count] pointer\n" );
358 ok( !strcmp( (*p_environ)[count + 1], "__winetest_dog=bark" ), "Couldn't get env var value\n" );
359 ok( getenv( "__winetest_dog" ) == strchr( (*p_environ)[count + 1], '=' ) + 1, "Expected getenv() to return pointer inside _environ[] entry\n" );
360 ok( count + 2 == env_get_entry_countA( *p_environ ), "Unexpected count\n" );
361 ok( _putenv( "__winetest_cat=" ) == 0, "Couldn't reset env vat\n" );
362 ok( second == (*p_environ)[count], "Expected _environ[count] to be second\n" );
363 ok( !strcmp( (*p_environ)[count], "__winetest_dog=bark" ), "Unexpected env var value\n" );
364 ok( count + 1 == env_get_entry_countA( *p_environ ), "Unexpected count\n" );
365 ok( _putenv( "__winetest_dog=" ) == 0, "Couldn't reset env var\n" );
366 ok( count == env_get_entry_countA( *p_environ ), "Unexpected count\n" );
367
368 /* in putenv, only changed variable is updated (no other reload of kernel info is done) */
369 ret = SetEnvironmentVariableA( "__winetest_cat", "meow" );
370 ok( ret, "SetEnvironmentVariableA failed: %lu\n", GetLastError() );
371 ok( _putenv( "__winetest_dog=bark" ) == 0, "Couldn't set env var\n" );
372 ok( getenv( "__winetest_cat" ) == NULL, "msvcrt env cache shouldn't have been updated\n" );
373 ok( _putenv( "__winetest_cat=" ) == 0, "Couldn't reset env var\n" );
374 ok( _putenv( "__winetest_dog=" ) == 0, "Couldn't reset env var\n" );
375
376 /* test setting unicode bits */
378 ret = WideCharToMultiByte( CP_ACP, 0, L"\u263a", -1, buf, ARRAY_SIZE(buf), 0, 0 );
379 ok( ret, "WideCharToMultiByte failed: %lu\n", GetLastError() );
380 ok( _wputenv( L"__winetest_cat=\u263a" ) == 0, "Couldn't set env var\n" );
381 ok( _wgetenv( L"__winetest_cat" ) && !wcscmp( _wgetenv( L"__winetest_cat" ), L"\u263a" ), "Couldn't retrieve env var\n" );
382 ok( getenv( "__winetest_cat" ) && !strcmp( getenv( "__winetest_cat" ), buf ), "Couldn't retrieve env var\n" );
383 ok( _wputenv( L"__winetest_cat=" ) == 0, "Couldn't reset env var\n" );
384
385 ret = WideCharToMultiByte( CP_ACP, 0, L"__winetest_\u263a", -1, buf, ARRAY_SIZE(buf), 0, 0 );
386 ok( ret, "WideCharToMultiByte failed: %lu\n", GetLastError() );
387 ok( _wputenv( L"__winetest_\u263a=bark" ) == 0, "Couldn't set env var\n" );
388 ok( _wgetenv( L"__winetest_\u263a" ) && !wcscmp( _wgetenv( L"__winetest_\u263a" ), L"bark"), "Couldn't retrieve env var\n" );
389 ok( getenv( buf ) && !strcmp( getenv( buf ), "bark"), "Couldn't retrieve env var %s\n", wine_dbgstr_a(buf) );
390 ok( _wputenv( L"__winetest_\u263a=" ) == 0, "Couldn't reset env var\n" );
391 ok( count == env_get_entry_countA( *p_environ ), "Unexpected modification of _environ[]\n" );
392}
#define EINVAL
Definition: acclib.h:90
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define ARRAY_SIZE(A)
Definition: main.h:20
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableA(IN LPCSTR lpName, IN LPCSTR lpValue)
Definition: environ.c:218
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
const GLint * first
Definition: glext.h:5794
static unsigned env_get_entry_countA(char **env)
Definition: environ.c:92
static const char * a_very_long_env_string
Definition: environ.c:32
#define errno
Definition: errno.h:18
const char int int int static __inline const char * wine_dbgstr_a(const char *s)
Definition: debug.h:187
int errno_t
Definition: corecrt.h:615
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by START_TEST().

◆ test_system()

static void test_system ( void  )
static

Definition at line 83 of file environ.c.

84{
85 int ret = system(NULL);
86 ok(ret == 1, "Expected system to return 1, got %d\n", ret);
87
88 ret = system("echo OK");
89 ok(ret == 0, "Expected system to return 0, got %d\n", ret);
90}
int __cdecl system(_In_opt_z_ const char *_Command)

Referenced by START_TEST().

◆ void()

static void ( __cdecl p_get_environ)
static

Variable Documentation

◆ a_very_long_env_string

const char* a_very_long_env_string
static
Initial value:
=
"LIBRARY_PATH="
"C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/;"
"C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/;"
"/mingw/lib/gcc/mingw32/3.4.2/;"
"/usr/lib/gcc/mingw32/3.4.2/;"
"C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/lib/mingw32/3.4.2/;"
"C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/lib/;"
"/mingw/mingw32/lib/mingw32/3.4.2/;"
"/mingw/mingw32/lib/;"
"/mingw/lib/mingw32/3.4.2/;"
"/mingw/lib/;"
"C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/../../../mingw32/3.4.2/;"
"C:/Program Files/GLBasic/Compiler/platform/Win32/Bin/../lib/gcc/mingw32/3.4.2/../../../;"
"/mingw/lib/mingw32/3.4.2/;"
"/mingw/lib/;"
"/lib/mingw32/3.4.2/;"
"/lib/;"
"/usr/lib/mingw32/3.4.2/;"
"/usr/lib/"

Definition at line 32 of file environ.c.

Referenced by test_environment_manipulation().

◆ p_environ

const char *static const wchar_t *static char const char* static char*** p_environ
static

Definition at line 63 of file environ.c.

Referenced by init(), test__environ(), and test_environment_manipulation().

◆ p_wenviron

WCHAR*** p_wenviron
static

Definition at line 64 of file environ.c.

Referenced by init(), and test__wenviron().

◆ size_t

const char *static const wchar_t *static char size_t

Definition at line 61 of file environ.c.